github.com/projecteru2/core@v0.0.0-20240321043226-06bcc1c23f58/auth/auth.go (about) 1 package auth 2 3 import ( 4 "context" 5 6 "github.com/projecteru2/core/auth/simple" 7 "github.com/projecteru2/core/types" 8 9 "google.golang.org/grpc" 10 ) 11 12 // Auth define auth obj 13 type Auth interface { 14 StreamInterceptor(srv any, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error 15 UnaryInterceptor(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) 16 } 17 18 // NewAuth return auth obj 19 func NewAuth(auth types.AuthConfig) Auth { 20 // TODO 这里可以组装其他的方法 21 return simple.NewBasicAuth(auth.Username, auth.Password) 22 } 23 24 // Credential for client 25 type Credential interface { 26 GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) 27 RequireTransportSecurity() bool 28 } 29 30 // NewCredential return credential obj 31 func NewCredential(auth types.AuthConfig) Credential { 32 // TODO 这里可以组装其他的方法 33 return simple.NewBasicCredential(auth.Username, auth.Password) 34 }