Documentation
¶
Index ¶
- Constants
- Variables
- func NewMetricsServer(serverConfig *config.ServerConfig, tracer tracing.Tracer) (http.Handler, error)
- func NewRouter(strictServer StrictServer, serverConfig *config.ServerConfig, ...) (http.Handler, error)
- func WithContextObject(key pkg.CtxKey, value any) func(next http.Handler) http.Handler
- func WithOtelTracer(next http.Handler) http.Handler
- func WithPrometheusMetrics(next http.Handler) http.Handler
- func WithRequestLogger(next http.Handler) http.Handler
- func WithTracedMiddleware(tracer tracing.Tracer, middleware func(next http.Handler) http.Handler) func(next http.Handler) http.Handler
- func WithUserID(tokenValidator func(r *http.Request) (oauth2.TokenInfo, error)) func(next http.Handler) http.Handler
- func WriteJSONResponse(w http.ResponseWriter, response any, status int)
- type AuthController
- type ControllerOption
- func WithAuthProvider(authProvider *authServer.Server) ControllerOption
- func WithConfig(conf config.ServerConfig) ControllerOption
- func WithLicenseService(licenseService service.LicenseService) ControllerOption
- func WithLogger(logger log.Logger) ControllerOption
- func WithNotificationService(notificationService service.NotificationService) ControllerOption
- func WithOrganizationService(organizationService service.OrganizationService) ControllerOption
- func WithPermissionService(permissionService service.PermissionService) ControllerOption
- func WithRoleService(roleService service.RoleService) ControllerOption
- func WithSystemService(systemService service.SystemService) ControllerOption
- func WithTodoService(todoService service.TodoService) ControllerOption
- func WithTracer(tracer tracing.Tracer) ControllerOption
- func WithUserService(userService service.UserService) ControllerOption
- type NotificationController
- type OrganizationController
- type PermissionController
- type Server
- type StrictServer
- type SystemController
- type TodoController
- type UserController
Constants ¶
const ( PathAuth = "/auth" PathLogin = "/login" PathOauthAuthorize = "/oauth/authorize" PathOauthToken = "/oauth/token" // #nosec )
const ( DefaultLimit = 10 // default limit for pagination DefaultOffset = 0 // default offset for pagination )
const ( PathRoot = "/" PathSwagger = "/swagger.json" PathMetrics = "/metrics" DefaultRequestThrottleLimit = 100 DefaultRequestThrottleBacklog = 1000 DefaultRequestThrottleTimeout = 10 * time.Second )
Variables ¶
var ( ErrAuthCredentials = errors.New("invalid credentials") // invalid credentials ErrAuthNoPermission = errors.New("no permission") // no permission ErrInvalidSwagger = errors.New("invalid swagger provided") // invalid swagger provided ErrNoAuthProvider = errors.New("no auth provider provided") // no auth provider provided ErrNoLicenseService = errors.New("no license service provided") // no license service provided ErrNoLogger = errors.New("no logger provided") // no logger provided ErrNoNotificationService = errors.New("no notification service provided") // no notification service provided ErrNoOrganizationService = errors.New("no organization service provided") // no organization service provided ErrNoPermissionService = errors.New("no permission service provided") // no permission service provided ErrNoRoleService = errors.New("no role service provided") // no role service provided ErrNoSystemService = errors.New("no system service provided") // no system service provided ErrNoTodoService = errors.New("no todo service provided") // no todo service provided ErrNoTracer = errors.New("no tracer provided") // no tracer provided ErrNoUserService = errors.New("no user service provided") // no user service provided )
Functions ¶
func NewMetricsServer ¶
func NewMetricsServer(serverConfig *config.ServerConfig, tracer tracing.Tracer) (http.Handler, error)
NewMetricsServer creates a new HTTP server for Prometheus metrics.
func NewRouter ¶
func NewRouter(strictServer StrictServer, serverConfig *config.ServerConfig, tracer tracing.Tracer) (http.Handler, error)
NewRouter creates a new HTTP router for the Server.
func WithContextObject ¶
WithContextObject returns a middleware that adds any value to the context associated with the given key.
func WithRequestLogger ¶
WithRequestLogger returns a middleware that logs the request.
The middleware depends on WithLogger. To use this middleware, you must call both of those first.
func WithTracedMiddleware ¶
func WithTracedMiddleware(tracer tracing.Tracer, middleware func(next http.Handler) http.Handler) func(next http.Handler) http.Handler
WithTracedMiddleware returns an HTTP middleware that traces the middleware execution by creating a new span and passing the context to the next handler.
func WithUserID ¶
func WithUserID(tokenValidator func(r *http.Request) (oauth2.TokenInfo, error)) func(next http.Handler) http.Handler
WithUserID returns a middleware that adds the user ID to the context, parsed from the Authorization header if present. Otherwise, an empty string is added.
func WriteJSONResponse ¶
func WriteJSONResponse(w http.ResponseWriter, response any, status int)
WriteJSONResponse writes the JSON response to the response writer.
Types ¶
type AuthController ¶
type AuthController interface { // Authorize handles the authorization of a request. Authorize(w http.ResponseWriter, r *http.Request) // Token handles the generation and renewal of a token. Token(w http.ResponseWriter, r *http.Request) // PasswordAuthHandler handles the authorization of a user with a password. // If the authorization is successful, the user ID is returned. Otherwise, // an error is returned instead. PasswordAuthHandler(ctx context.Context, clientID, email, password string) (string, error) // UserAuthHandler handles the authorization of a user. If the // authorization is successful, the user ID is returned. Otherwise, an // error is returned instead. UserAuthHandler(w http.ResponseWriter, r *http.Request) (string, error) // ClientAuthHandler handles the client authorization. ClientAuthHandler(w http.ResponseWriter, r *http.Request) // LoginHandler handles the login of a user. LoginHandler(w http.ResponseWriter, r *http.Request) // ValidateBearerToken validates a bearer token and returns the token info // if the token is valid. Otherwise, an error is returned instead. ValidateBearerToken(r *http.Request) (oauth2.TokenInfo, error) // ValidateTokenHandler handles the validation of a token. ValidateTokenHandler(r *http.Request) error }
AuthController provides handlers for authentication and authorization.
func NewAuthController ¶
func NewAuthController(opts ...ControllerOption) (AuthController, error)
NewAuthController creates a new AuthController.
type ControllerOption ¶
type ControllerOption func(*baseController) error
ControllerOption is a function that can be used to configure a controller.
func WithAuthProvider ¶
func WithAuthProvider(authProvider *authServer.Server) ControllerOption
WithAuthProvider sets the authServer provider for the controller.
func WithConfig ¶
func WithConfig(conf config.ServerConfig) ControllerOption
WithConfig sets the config for the controller.
func WithLicenseService ¶
func WithLicenseService(licenseService service.LicenseService) ControllerOption
WithLicenseService sets the license service for the controller.
func WithLogger ¶
func WithLogger(logger log.Logger) ControllerOption
WithLogger sets the logger for the controller.
func WithNotificationService ¶
func WithNotificationService(notificationService service.NotificationService) ControllerOption
WithNotificationService sets the notification service for the controller.
func WithOrganizationService ¶
func WithOrganizationService(organizationService service.OrganizationService) ControllerOption
WithOrganizationService sets the organization service for the controller.
func WithPermissionService ¶
func WithPermissionService(permissionService service.PermissionService) ControllerOption
WithPermissionService sets the permission service for the controller.
func WithRoleService ¶
func WithRoleService(roleService service.RoleService) ControllerOption
WithRoleService sets the role service for the controller.
func WithSystemService ¶
func WithSystemService(systemService service.SystemService) ControllerOption
WithSystemService sets the system service for the controller.
func WithTodoService ¶
func WithTodoService(todoService service.TodoService) ControllerOption
WithTodoService sets the todo service for the controller.
func WithTracer ¶
func WithTracer(tracer tracing.Tracer) ControllerOption
WithTracer sets the tracer for the controller.
func WithUserService ¶
func WithUserService(userService service.UserService) ControllerOption
WithUserService sets the user service for the controller.
type NotificationController ¶
type NotificationController interface { V1NotificationGet(ctx context.Context, request api.V1NotificationGetRequestObject) (api.V1NotificationGetResponseObject, error) V1NotificationsGet(ctx context.Context, request api.V1NotificationsGetRequestObject) (api.V1NotificationsGetResponseObject, error) V1NotificationUpdate(ctx context.Context, request api.V1NotificationUpdateRequestObject) (api.V1NotificationUpdateResponseObject, error) V1NotificationDelete(ctx context.Context, request api.V1NotificationDeleteRequestObject) (api.V1NotificationDeleteResponseObject, error) }
NotificationController is the controller for the notification endpoints.
func NewNotificationController ¶
func NewNotificationController(opts ...ControllerOption) (NotificationController, error)
NewNotificationController creates a new NotificationController.
type OrganizationController ¶
type OrganizationController interface { V1OrganizationsGet(ctx context.Context, request api.V1OrganizationsGetRequestObject) (api.V1OrganizationsGetResponseObject, error) V1OrganizationsCreate(ctx context.Context, request api.V1OrganizationsCreateRequestObject) (api.V1OrganizationsCreateResponseObject, error) V1OrganizationDelete(ctx context.Context, request api.V1OrganizationDeleteRequestObject) (api.V1OrganizationDeleteResponseObject, error) V1OrganizationGet(ctx context.Context, request api.V1OrganizationGetRequestObject) (api.V1OrganizationGetResponseObject, error) V1OrganizationUpdate(ctx context.Context, request api.V1OrganizationUpdateRequestObject) (api.V1OrganizationUpdateResponseObject, error) V1OrganizationMembersGet(ctx context.Context, request api.V1OrganizationMembersGetRequestObject) (api.V1OrganizationMembersGetResponseObject, error) V1OrganizationMembersAdd(ctx context.Context, request api.V1OrganizationMembersAddRequestObject) (api.V1OrganizationMembersAddResponseObject, error) V1OrganizationMemberRemove(ctx context.Context, request api.V1OrganizationMemberRemoveRequestObject) (api.V1OrganizationMemberRemoveResponseObject, error) V1OrganizationRolesCreate(ctx context.Context, request api.V1OrganizationRolesCreateRequestObject) (api.V1OrganizationRolesCreateResponseObject, error) V1OrganizationRoleGet(ctx context.Context, request api.V1OrganizationRoleGetRequestObject) (api.V1OrganizationRoleGetResponseObject, error) V1OrganizationRolesGet(ctx context.Context, request api.V1OrganizationRolesGetRequestObject) (api.V1OrganizationRolesGetResponseObject, error) V1OrganizationRoleUpdate(ctx context.Context, request api.V1OrganizationRoleUpdateRequestObject) (api.V1OrganizationRoleUpdateResponseObject, error) V1OrganizationRoleDelete(ctx context.Context, request api.V1OrganizationRoleDeleteRequestObject) (api.V1OrganizationRoleDeleteResponseObject, error) V1OrganizationRoleMembersGet(ctx context.Context, request api.V1OrganizationRoleMembersGetRequestObject) (api.V1OrganizationRoleMembersGetResponseObject, error) V1OrganizationRoleMembersAdd(ctx context.Context, request api.V1OrganizationRoleMembersAddRequestObject) (api.V1OrganizationRoleMembersAddResponseObject, error) V1OrganizationRoleMemberRemove(ctx context.Context, request api.V1OrganizationRoleMemberRemoveRequestObject) (api.V1OrganizationRoleMemberRemoveResponseObject, error) }
OrganizationController is a controller for organization endpoints.
func NewOrganizationController ¶
func NewOrganizationController(opts ...ControllerOption) (OrganizationController, error)
NewOrganizationController creates a new OrganizationController.
type PermissionController ¶
type PermissionController interface { V1PermissionsCreate(ctx context.Context, request api.V1PermissionsCreateRequestObject) (api.V1PermissionsCreateResponseObject, error) V1PermissionGet(ctx context.Context, request api.V1PermissionGetRequestObject) (api.V1PermissionGetResponseObject, error) V1PermissionUpdate(ctx context.Context, request api.V1PermissionUpdateRequestObject) (api.V1PermissionUpdateResponseObject, error) V1PermissionDelete(ctx context.Context, request api.V1PermissionDeleteRequestObject) (api.V1PermissionDeleteResponseObject, error) V1PermissionResourceGet(ctx context.Context, request api.V1PermissionResourceGetRequestObject) (api.V1PermissionResourceGetResponseObject, error) V1PermissionHasRelations(ctx context.Context, request api.V1PermissionHasRelationsRequestObject) (api.V1PermissionHasRelationsResponseObject, error) V1PermissionHasSystemRole(ctx context.Context, request api.V1PermissionHasSystemRoleRequestObject) (api.V1PermissionHasSystemRoleResponseObject, error) }
PermissionController is a controller for system endpoints.
func NewPermissionController ¶
func NewPermissionController(opts ...ControllerOption) (PermissionController, error)
NewPermissionController creates a new PermissionController.
type Server ¶
type Server interface { api.ServerInterface AuthController InternalErrorHandler(err error) *authErrors.Response ResponseErrorHandler(r *authErrors.Response) PreRedirectErrorHandler(w http.ResponseWriter, r *authServer.AuthorizeRequest, err error) }
Server is the type alias for the generated server interface.
type StrictServer ¶
type StrictServer interface { api.StrictServerInterface AuthController InternalErrorHandler(err error) (re *authErrors.Response) ResponseErrorHandler(r *authErrors.Response) PreRedirectErrorHandler(w http.ResponseWriter, r *authServer.AuthorizeRequest, err error) }
StrictServer is the type alias for the generated server interface.
func NewServer ¶
func NewServer(opts ...ControllerOption) (StrictServer, error)
NewServer creates a new HTTP server.
type SystemController ¶
type SystemController interface { V1SystemHealth(ctx context.Context, request api.V1SystemHealthRequestObject) (api.V1SystemHealthResponseObject, error) V1SystemHeartbeat(ctx context.Context, request api.V1SystemHeartbeatRequestObject) (api.V1SystemHeartbeatResponseObject, error) V1SystemVersion(ctx context.Context, request api.V1SystemVersionRequestObject) (api.V1SystemVersionResponseObject, error) V1SystemLicense(ctx context.Context, request api.V1SystemLicenseRequestObject) (api.V1SystemLicenseResponseObject, error) }
SystemController is a controller for system endpoints.
func NewSystemController ¶
func NewSystemController(opts ...ControllerOption) (SystemController, error)
NewSystemController creates a new SystemController.
type TodoController ¶
type TodoController interface { V1TodosCreate(ctx context.Context, request api.V1TodosCreateRequestObject) (api.V1TodosCreateResponseObject, error) V1TodoGet(ctx context.Context, request api.V1TodoGetRequestObject) (api.V1TodoGetResponseObject, error) V1TodosGet(ctx context.Context, request api.V1TodosGetRequestObject) (api.V1TodosGetResponseObject, error) V1TodoUpdate(ctx context.Context, request api.V1TodoUpdateRequestObject) (api.V1TodoUpdateResponseObject, error) V1TodoDelete(ctx context.Context, request api.V1TodoDeleteRequestObject) (api.V1TodoDeleteResponseObject, error) }
TodoController is the controller for the todo endpoints.
func NewTodoController ¶
func NewTodoController(opts ...ControllerOption) (TodoController, error)
NewTodoController creates a new TodoController.
type UserController ¶
type UserController interface { V1UsersCreate(ctx context.Context, request api.V1UsersCreateRequestObject) (api.V1UsersCreateResponseObject, error) V1UserGet(ctx context.Context, request api.V1UserGetRequestObject) (api.V1UserGetResponseObject, error) V1UsersGet(ctx context.Context, request api.V1UsersGetRequestObject) (api.V1UsersGetResponseObject, error) V1UserUpdate(ctx context.Context, request api.V1UserUpdateRequestObject) (api.V1UserUpdateResponseObject, error) V1UserDelete(ctx context.Context, request api.V1UserDeleteRequestObject) (api.V1UserDeleteResponseObject, error) }
UserController is a controller for user endpoints.
func NewUserController ¶
func NewUserController(opts ...ControllerOption) (UserController, error)
NewUserController creates a new UserController.