Documentation ¶
Index ¶
- type CircleCensorClient
- type Client
- func (c Client) CensorText(ctx context.Context, text string) string
- func (c Client) CensorTextInCircle(ctx context.Context, text, circleID string) string
- func (c Client) ContainsBlockedURL(ctx context.Context, text string) bool
- func (c Client) HasForbiddenWords(ctx context.Context, text string) bool
- func (c Client) HasForbiddenWordsInCircle(ctx context.Context, text, circleID string) bool
- func (c Client) IsBlockedURL(ctx context.Context, url string) bool
- type GlobalCensorClient
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CircleCensorClient ¶
type CircleCensorClient interface { GetCensoredWords( context.Context, *circlePb.GetCensoredWordsRequest, ...grpc.CallOption, ) (*circlePb.GetCensoredWordsResponse, error) }
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient( global GlobalCensorClient, circle CircleCensorClient, ) Client
func (Client) CensorText ¶
Example ¶
package main import ( "context" "fmt" "github.com/golang/mock/gomock" "gitlab.com/picnic-app/backend/libs/golang/censorship" "gitlab.com/picnic-app/backend/libs/golang/logger" adminMock "gitlab.com/picnic-app/backend/libs/golang/protobuf-registry/gen/admin-api/admin/v1/mockgen" circleMock "gitlab.com/picnic-app/backend/libs/golang/protobuf-registry/gen/circle-api/circle/v1/mockgen" ) type reporter struct{} func (r reporter) Errorf(format string, args ...interface{}) { logger.Errorf(context.Background(), format, args...) } func (r reporter) Fatalf(format string, args ...interface{}) { logger.Fatalf(context.Background(), format, args...) } var ( ctx = context.Background() ctrl = gomock.NewController(reporter{}) globalClient = adminMock.NewMockAdminAPIClient(ctrl) circleClient = circleMock.NewMockCircleAPIClient(ctrl) ) func main() { cli := censorship.NewClient(globalClient, circleClient) censoredText := cli.CensorText(ctx, "Using CENSORED-WORD in text") fmt.Println(censoredText) }
Output: Using ************* in text
func (Client) CensorTextInCircle ¶
Example ¶
package main import ( "context" "fmt" "github.com/golang/mock/gomock" "gitlab.com/picnic-app/backend/libs/golang/censorship" "gitlab.com/picnic-app/backend/libs/golang/logger" adminMock "gitlab.com/picnic-app/backend/libs/golang/protobuf-registry/gen/admin-api/admin/v1/mockgen" circleMock "gitlab.com/picnic-app/backend/libs/golang/protobuf-registry/gen/circle-api/circle/v1/mockgen" ) type reporter struct{} func (r reporter) Errorf(format string, args ...interface{}) { logger.Errorf(context.Background(), format, args...) } func (r reporter) Fatalf(format string, args ...interface{}) { logger.Fatalf(context.Background(), format, args...) } const circleID = "circle id" var ( ctx = context.Background() ctrl = gomock.NewController(reporter{}) globalClient = adminMock.NewMockAdminAPIClient(ctrl) circleClient = circleMock.NewMockCircleAPIClient(ctrl) ) func main() { cli := censorship.NewClient(globalClient, circleClient) censoredText := cli.CensorTextInCircle(ctx, "Using CENSORED-IN-CIRCLE-WORD in text", circleID) fmt.Println(censoredText) }
Output: Using *********************** in text
func (Client) ContainsBlockedURL ¶ added in v1.0.2
Example ¶
package main import ( "context" "fmt" "github.com/golang/mock/gomock" "gitlab.com/picnic-app/backend/libs/golang/censorship" "gitlab.com/picnic-app/backend/libs/golang/logger" adminMock "gitlab.com/picnic-app/backend/libs/golang/protobuf-registry/gen/admin-api/admin/v1/mockgen" circleMock "gitlab.com/picnic-app/backend/libs/golang/protobuf-registry/gen/circle-api/circle/v1/mockgen" ) type reporter struct{} func (r reporter) Errorf(format string, args ...interface{}) { logger.Errorf(context.Background(), format, args...) } func (r reporter) Fatalf(format string, args ...interface{}) { logger.Fatalf(context.Background(), format, args...) } var ( ctx = context.Background() ctrl = gomock.NewController(reporter{}) globalClient = adminMock.NewMockAdminAPIClient(ctrl) circleClient = circleMock.NewMockCircleAPIClient(ctrl) ) func main() { cli := censorship.NewClient(globalClient, circleClient) blocked := cli.ContainsBlockedURL(ctx, "Using WWW.BLOCKED-URL.COM in text") fmt.Println(blocked) }
Output: true
func (Client) HasForbiddenWords ¶
Example ¶
package main import ( "context" "fmt" "github.com/golang/mock/gomock" "gitlab.com/picnic-app/backend/libs/golang/censorship" "gitlab.com/picnic-app/backend/libs/golang/logger" adminMock "gitlab.com/picnic-app/backend/libs/golang/protobuf-registry/gen/admin-api/admin/v1/mockgen" circleMock "gitlab.com/picnic-app/backend/libs/golang/protobuf-registry/gen/circle-api/circle/v1/mockgen" ) type reporter struct{} func (r reporter) Errorf(format string, args ...interface{}) { logger.Errorf(context.Background(), format, args...) } func (r reporter) Fatalf(format string, args ...interface{}) { logger.Fatalf(context.Background(), format, args...) } var ( ctx = context.Background() ctrl = gomock.NewController(reporter{}) globalClient = adminMock.NewMockAdminAPIClient(ctrl) circleClient = circleMock.NewMockCircleAPIClient(ctrl) ) func main() { cli := censorship.NewClient(globalClient, circleClient) found := cli.HasForbiddenWords(ctx, "Using CENSORED-WORD in text") fmt.Println(found) }
Output: true
func (Client) HasForbiddenWordsInCircle ¶
Example ¶
package main import ( "context" "fmt" "github.com/golang/mock/gomock" "gitlab.com/picnic-app/backend/libs/golang/censorship" "gitlab.com/picnic-app/backend/libs/golang/logger" adminMock "gitlab.com/picnic-app/backend/libs/golang/protobuf-registry/gen/admin-api/admin/v1/mockgen" circleMock "gitlab.com/picnic-app/backend/libs/golang/protobuf-registry/gen/circle-api/circle/v1/mockgen" ) type reporter struct{} func (r reporter) Errorf(format string, args ...interface{}) { logger.Errorf(context.Background(), format, args...) } func (r reporter) Fatalf(format string, args ...interface{}) { logger.Fatalf(context.Background(), format, args...) } const circleID = "circle id" var ( ctx = context.Background() ctrl = gomock.NewController(reporter{}) globalClient = adminMock.NewMockAdminAPIClient(ctrl) circleClient = circleMock.NewMockCircleAPIClient(ctrl) ) func main() { cli := censorship.NewClient(globalClient, circleClient) found := cli.HasForbiddenWordsInCircle(ctx, "Using CENSORED-WORD in text", circleID) fmt.Println(found) }
Output: true
func (Client) IsBlockedURL ¶
Example ¶
package main import ( "context" "fmt" "github.com/golang/mock/gomock" "gitlab.com/picnic-app/backend/libs/golang/censorship" "gitlab.com/picnic-app/backend/libs/golang/logger" adminMock "gitlab.com/picnic-app/backend/libs/golang/protobuf-registry/gen/admin-api/admin/v1/mockgen" circleMock "gitlab.com/picnic-app/backend/libs/golang/protobuf-registry/gen/circle-api/circle/v1/mockgen" ) type reporter struct{} func (r reporter) Errorf(format string, args ...interface{}) { logger.Errorf(context.Background(), format, args...) } func (r reporter) Fatalf(format string, args ...interface{}) { logger.Fatalf(context.Background(), format, args...) } var ( ctx = context.Background() ctrl = gomock.NewController(reporter{}) globalClient = adminMock.NewMockAdminAPIClient(ctrl) circleClient = circleMock.NewMockCircleAPIClient(ctrl) ) func main() { cli := censorship.NewClient(globalClient, circleClient) blocked := cli.IsBlockedURL(ctx, "WWW.BLOCKED-URL.COM") fmt.Println(blocked) }
Output: true
type GlobalCensorClient ¶
type GlobalCensorClient interface { GetCensoredWords( context.Context, *adminPb.GetCensoredWordsRequest, ...grpc.CallOption, ) (*adminPb.GetCensoredWordsResponse, error) GetBlockedURLs( context.Context, *adminPb.GetBlockedURLsRequest, ...grpc.CallOption, ) (*adminPb.GetBlockedURLsResponse, error) }
Click to show internal directories.
Click to hide internal directories.