github.com/wfusion/gofusion@v1.1.14/common/infra/watermill/pubsub/sql/topic.go (about) 1 package sql 2 3 import ( 4 "regexp" 5 6 "github.com/pkg/errors" 7 ) 8 9 var disallowedTopicCharacters = regexp.MustCompile(`[^A-Za-z0-9\-\$\:\.\_]`) 10 11 var ErrInvalidTopicName = errors.New("topic name should not contain characters matched by " + disallowedTopicCharacters.String()) 12 13 // validateTopicName checks if the topic name contains any characters which could be unsuitable for the SQL Pub/Sub. 14 // Topics are translated into SQL tables and patched into some queries, so this is done to prevent injection as well. 15 func validateTopicName(topic string) error { 16 if disallowedTopicCharacters.MatchString(topic) { 17 return errors.Wrap(ErrInvalidTopicName, topic) 18 } 19 20 return nil 21 }