api

package
v0.0.0-...-9928b23 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = &ErrResponse{HTTPStatusCode: 404, StatusText: "Resource not found."}

Functions

func AdminRouter

func AdminRouter(ctx context.Context) chi.Router

A completely separate router for administrator routes

func ErrInternalServer

func ErrInternalServer(err error) render.Renderer

func ErrInvalidRequest

func ErrInvalidRequest(err error) render.Renderer

func ErrRender

func ErrRender(err error) render.Renderer

func GenerateDocs

func GenerateDocs(r chi.Router, docs string)

func IsAlphaNumeric

func IsAlphaNumeric(s string) bool

Utilities

func IsLower

func IsLower(s string) bool

func LoginRouter

func LoginRouter(ctx context.Context) http.Handler

func PirgsRouter

func PirgsRouter(ctx context.Context) http.Handler

func StartsWithLetter

func StartsWithLetter(s string) bool

func UsersRouter

func UsersRouter(ctx context.Context) http.Handler

func ValidatePirgName

func ValidatePirgName(name string) error

Types

type ApiResponse

type ApiResponse struct {
	Role    string            `json:"role"`
	Results []render.Renderer `json:"results"`
}

func (*ApiResponse) Render

func (u *ApiResponse) Render(w http.ResponseWriter, r *http.Request) error

type ErrResponse

type ErrResponse struct {
	Err            error `json:"-"` // low-level runtime error
	HTTPStatusCode int   `json:"-"` // http response status code

	StatusText string `json:"status"`          // user-level status message
	AppCode    int64  `json:"code,omitempty"`  // application-specific error code
	ErrorText  string `json:"error,omitempty"` // application-level error message, for debugging
}

ErrResponse renderer type for handling all sorts of errors.

In the best case scenario, the excellent github.com/pkg/errors package helps reveal information on the error, setting it on Err, and in the Render() method, using it to set the application-specific error code in AppCode.

func (*ErrResponse) Render

func (e *ErrResponse) Render(w http.ResponseWriter, r *http.Request) error

type PirgHandler

type PirgHandler struct {
	// contains filtered or unexported fields
}

func (*PirgHandler) CreatePirg

func (h *PirgHandler) CreatePirg(w http.ResponseWriter, r *http.Request)

CreatePirg creates a new Pirg

func (*PirgHandler) DeletePirg

func (h *PirgHandler) DeletePirg(w http.ResponseWriter, r *http.Request)

DeletePirg deletes a Pirg

func (*PirgHandler) GetAllPirgs

func (h *PirgHandler) GetAllPirgs(w http.ResponseWriter, r *http.Request)

GetAllPirgs returns all existing Pirgs

func (*PirgHandler) GetPirg

func (h *PirgHandler) GetPirg(w http.ResponseWriter, r *http.Request)

GetPirg returns the Pirg by the ID in the URL

func (*PirgHandler) PirgCtx

func (h *PirgHandler) PirgCtx(next http.Handler) http.Handler

PirgCtx middleware is used to load a Pirg object from /Pirgs/{Pirgname} requests and then attach it to the request context. In case of failure the request is aborted and a 404 error response is sent to the client.

func (*PirgHandler) UpdatePirg

func (h *PirgHandler) UpdatePirg(w http.ResponseWriter, r *http.Request)

UpdatePirg updates a Pirg

type PirgRequest

type PirgRequest struct {
	Name     string `json:"name"`
	OwnerId  int    `json:"owner_id"`
	AdminIds []int  `json:"admin_ids"`
	UserIds  []int  `json:"user_ids"`
}

func (*PirgRequest) Bind

func (u *PirgRequest) Bind(r *http.Request) error

type PirgResponse

type PirgResponse struct {
	Id         int       `json:"id"`
	Name       string    `json:"name"`
	OwnerId    int       `json:"owner_id"`
	AdminIds   []int     `json:"admin_ids"`
	UserIds    []int     `json:"user_ids"`
	CreatedAt  time.Time `json:"created_at"`
	ModifiedAt time.Time `json:"modified_at"`
}

func (*PirgResponse) Bind

func (u *PirgResponse) Bind(r *http.Request) error

func (*PirgResponse) Render

func (u *PirgResponse) Render(w http.ResponseWriter, r *http.Request) error

type PirgStub

type PirgStub struct {
	Id       int
	Pirgname string
}

type UserHandler

type UserHandler struct {
	// contains filtered or unexported fields
}

func (*UserHandler) CreateUser

func (h *UserHandler) CreateUser(w http.ResponseWriter, r *http.Request)

CreateUser creates a new user

func (*UserHandler) DeleteUser

func (h *UserHandler) DeleteUser(w http.ResponseWriter, r *http.Request)

DeleteUser deletes a user

func (*UserHandler) GetAllUsers

func (h *UserHandler) GetAllUsers(w http.ResponseWriter, r *http.Request)

GetAllUsers returns all existing users

func (*UserHandler) GetUser

func (h *UserHandler) GetUser(w http.ResponseWriter, r *http.Request)

GetUser returns the user in the request context

func (*UserHandler) UpdateUser

func (h *UserHandler) UpdateUser(w http.ResponseWriter, r *http.Request)

UpdateUser updates a user

func (*UserHandler) UserCtx

func (h *UserHandler) UserCtx(next http.Handler) http.Handler

UserCtx middleware is used to load a User object from /users/{username} requests and then attach it to the request context. In case of failure the request is aborted and a 404 error response is sent to the client.

type UserRequest

type UserRequest struct {
	Username  string `json:"username"`
	Email     string `json:"email"`
	FirstName string `json:"firstname"`
	LastName  string `json:"lastname"`
}

func (*UserRequest) Bind

func (u *UserRequest) Bind(r *http.Request) error

type UserResponse

type UserResponse struct {
	Id         int       `json:"id"`
	Username   string    `json:"username"`
	Email      string    `json:"email"`
	FirstName  string    `json:"firstname"`
	LastName   string    `json:"lastname"`
	CreatedAt  time.Time `json:"created_at"`
	ModifiedAt time.Time `json:"modified_at"`
}

func (*UserResponse) Bind

func (u *UserResponse) Bind(r *http.Request) error

func (*UserResponse) Render

func (u *UserResponse) Render(w http.ResponseWriter, r *http.Request) error

Jump to

Keyboard shortcuts

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