package exampleservice import ( "context" "fmt" service1 "goa_example/gen/service1" "log" "goa.design/goa/v3/security" ) // Service1 service example implementation. // The example methods log the requests and return zero values. type service1srvc struct { logger *log.Logger } // NewService1 returns the Service1 service implementation. func NewService1(logger *log.Logger) service1.Service { return &service1srvc{logger} } // BasicAuth implements the authorization logic for service "Service1" for the // "basic" security scheme. func (s *service1srvc) BasicAuth(ctx context.Context, user, pass string, scheme *security.BasicScheme) (context.Context, error) { // // TBD: add authorization logic. // // In case of authorization failure this function should return // one of the generated error structs, e.g.: // // return ctx, myservice.MakeUnauthorizedError("invalid token") // // Alternatively this function may return an instance of // goa.ServiceError with a Name field value that matches one of // the design error names, e.g: // // return ctx, goa.PermanentError("unauthorized", "invalid token") // return ctx, fmt.Errorf("not implemented") } // JWTAuth implements the authorization logic for service "Service1" for the // "jwt" security scheme. func (s *service1srvc) JWTAuth(ctx context.Context, token string, scheme *security.JWTScheme) (context.Context, error) { // // TBD: add authorization logic. // // In case of authorization failure this function should return // one of the generated error structs, e.g.: // // return ctx, myservice.MakeUnauthorizedError("invalid token") // // Alternatively this function may return an instance of // goa.ServiceError with a Name field value that matches one of // the design error names, e.g: // // return ctx, goa.PermanentError("unauthorized", "invalid token") // return ctx, fmt.Errorf("not implemented") } // Signin implements signin. func (s *service1srvc) Signin(ctx context.Context, p *service1.SigninPayload) (res *service1.Creds, err error) { res = &service1.Creds{} s.logger.Print("service1.signin") return } // 这是一个需要JWT认证的接口 func (s *service1srvc) Secure(ctx context.Context, p *service1.SecurePayload) (res string, err error) { s.logger.Print("service1.secure") return }