api

package
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 1, 2025 License: Apache-2.0 Imports: 18 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const AdminGroupName = "Admin"

AdminGroupName - Has a string to define Admins

View Source
const DceCtxKey dceCtxKeyType = "dce"

DceCtxKey - Context Key

View Source
const UserGroupName = "User"

UserGroupName - Has the string to define Users

Variables

View Source
var EmptyQueryString []string

EmptyQueryString - Empty query string to prevent

Functions

func BuildNextURL

func BuildNextURL(u url.URL, i interface{}) (url.URL, error)

BuildNextURL merges the next parameters of pagination into the request parameters and returns an API URL.

func NewRouter

func NewRouter(routes Routes) *mux.Router

NewRouter - Create a new router

func WriteAPIErrorResponse

func WriteAPIErrorResponse(w http.ResponseWriter, err error)

WriteAPIErrorResponse writes an error to the ResponseWriter

func WriteAPIResponse

func WriteAPIResponse(w http.ResponseWriter, status int, body interface{})

WriteAPIResponse writes the response out to the provided ResponseWriter

Types

type Controller

type Controller interface {
	// Call is invoked when an instance of a controller is handling a request. Returns a response to be returned to the
	// API consumer.
	Call(ctx context.Context, req *events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error)
}

Controller is the base controller interface for API Gateway Lambda handlers.

type Route

type Route struct {
	Name        string
	Method      string
	Pattern     string
	Queries     []string
	HandlerFunc http.HandlerFunc
}

Route - A route

type Router

type Router struct {
	ResourceName     string
	ListController   Controller
	DeleteController Controller
	GetController    Controller
	CreateController Controller
	UserDetails      UserDetailer
}

Router structure holds AccountController instance for request

func (*Router) Route

Route - provides a router for the given resource

type Routes

type Routes []Route

Routes - The list of Routes

type User

type User struct {
	Username string
	Role     string
}

User - Has the username and their role

func (*User) Authorize

func (u *User) Authorize(principalID string) error

Authorize returns an error if the user is not authorized to act on the principalID

type UserDetailer

type UserDetailer interface {
	GetUser(reqCtx *events.APIGatewayProxyRequestContext) *User
}

UserDetailer - used for mocking tests

type UserDetails

type UserDetails struct {
	CognitoUserPoolID        string `env:"COGNITO_USER_POOL_ID" defaultEnv:"DefaultCognitoUserPoolId"`
	RolesAttributesAdminName string `env:"COGNITO_ROLES_ATTRIBUTE_ADMIN_NAME" defaultEnv:"DefaultCognitoAdminName"`
	CognitoClient            awsiface.CognitoIdentityProviderAPI
}

UserDetails - Gets User information

func (*UserDetails) GetUser

GetUser - Gets the username and role out of an http request object Assumes that the request is via a Lambda event. Uses cognito metadata from the request to determine the user info. If the request is not authenticated with cognito, returns a generic admin user: User{ Username: "", Role: "Admin" }

type UserDetailsMiddleware

type UserDetailsMiddleware struct {
	GorillaMuxAdapter *gorillamux.GorillaMuxAdapter
	UserDetailer      UserDetailer
}

func (*UserDetailsMiddleware) Middleware

func (u *UserDetailsMiddleware) Middleware(next http.Handler) http.Handler

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL