handler

package
v0.0.0-...-498e44a Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdminMiddleware

func AdminMiddleware(next http.Handler) http.Handler

contextから管理者権限の有無を確認する

func AuthMiddleware

func AuthMiddleware(j *auth.JWTer) func(next http.Handler) http.Handler

リクエストスコープな値(ユーザーID、ロール)をcontextへ埋め込む アクセストークンがない場合はリクエストの処理が終了させる

func RespondJSON

func RespondJSON(ctx context.Context, w http.ResponseWriter, body any, status int)

JSONのレスポンスを書き込むヘルパー

Types

type AddExercise

type AddExercise struct {
	Service   AddExerciseService
	Validator *validator.Validate
}

func (*AddExercise) ServeHTTP

func (ae *AddExercise) ServeHTTP(w http.ResponseWriter, r *http.Request)

リクエストボディを読み込み、バリデーション 結果が正常ならエクササイズを作成し、保存する レスポンスボディにRDBMSにより発行されたIDを書き込む

type AddExerciseService

type AddExerciseService interface {
	AddExercise(ctx context.Context, title, description string) (*entity.Exercise, error)
}

type DeleteExercise

type DeleteExercise struct {
	Service DeleteExerciseService
	*GetExercise
}

func (*DeleteExercise) ServeHTTP

func (de *DeleteExercise) ServeHTTP(w http.ResponseWriter, r *http.Request)

type DeleteExerciseService

type DeleteExerciseService interface {
	DeleteExercise(ctx context.Context, id entity.ExerciseID) error
}

type ErrResponse

type ErrResponse struct {
	Message string   `json:"message"`
	Details []string `json:"details,omitempty"`
}

統一したJSONフォーマットでエラーを返すための型

type GetExercise

type GetExercise struct {
	Service GetExerciseService
}

func (*GetExercise) ServeHTTP

func (ge *GetExercise) ServeHTTP(w http.ResponseWriter, r *http.Request)

type GetExerciseService

type GetExerciseService interface {
	GetExercise(ctx context.Context, id entity.ExerciseID) (*entity.Exercise, error)
}

type ListExercise

type ListExercise struct {
	Service ListExercisesService
}

func (*ListExercise) ServeHTTP

func (le *ListExercise) ServeHTTP(w http.ResponseWriter, r *http.Request)

DBから一覧を取得し、レスポンスボディに書き込む

type ListExercisesService

type ListExercisesService interface {
	ListExercises(ctx context.Context) (entity.Exercises, error)
}

type Login

type Login struct {
	Service   LoginService
	Validator *validator.Validate
}

func (*Login) ServeHTTP

func (l *Login) ServeHTTP(w http.ResponseWriter, r *http.Request)

type LoginService

type LoginService interface {
	Login(ctx context.Context, name, pw string) (string, error)
}

type RegisterUser

type RegisterUser struct {
	Service   RegisterUserService
	Validator *validator.Validate
}

func (*RegisterUser) ServeHTTP

func (ru *RegisterUser) ServeHTTP(w http.ResponseWriter, r *http.Request)

type RegisterUserService

type RegisterUserService interface {
	RegisterUser(ctx context.Context, name, password, role string) (*entity.User, error)
}

type UpdateExercise

type UpdateExercise struct {
	Service   UpdateExerciseService
	Validator *validator.Validate
	*GetExercise
}

func (*UpdateExercise) ServeHTTP

func (ue *UpdateExercise) ServeHTTP(w http.ResponseWriter, r *http.Request)

type UpdateExerciseService

type UpdateExerciseService interface {
	UpdateExercise(ctx context.Context, id entity.ExerciseID, title, description string) error
}

Jump to

Keyboard shortcuts

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