helloweb

package
v0.0.0-...-2680af6 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TodoStatusUnknown = "UNKNOWN"
	TodoStatusNew     = "NEW"
	TodoStatusDoing   = "DOING"
	TodoStatusPending = "PENDING"
	TodoStatusDone    = "DONE"
)
View Source
const (
	MsgOK = "ok"
)

Variables

This section is empty.

Functions

func FileServerFS

func FileServerFS(r chi.Router, path string, root fs.FS)

FileServerFS conveniently sets up a http.FileServer handler to serve static files from a fs.FS.

func NewServer

func NewServer(todoStore TodoStore, options ...Option) (*server, error)

Types

type API

type API struct {
	Status    int
	Message   string
	Data      any
	Err       error
	RequestID string
	Extra     map[string]any
}

API ...

func (*API) ServeHTTP

func (api *API) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*API) WithExtra

func (api *API) WithExtra(extra map[string]any) *API

func (*API) WithMessage

func (api *API) WithMessage(msg string) *API

func (*API) WithRequestID

func (api *API) WithRequestID(id string) *API

func (*API) WithStatus

func (api *API) WithStatus(status int) *API

type APIHandler

type APIHandler func(w http.ResponseWriter, r *http.Request) *API

type CreateTodoResponse

type CreateTodoResponse struct {
	ID int64 `json:"id"`
}

type DeleteTodoResponse

type DeleteTodoResponse struct {
	ID int64 `json:"id"`
}

type GetTodoResponse

type GetTodoResponse struct {
	Todo Todo `json:"todo"`
}

type ListTodosResponse

type ListTodosResponse struct {
	Todos []Todo `json:"todos"`
}

type Option

type Option func(*options)

func WithEnv

func WithEnv(env string) Option

func WithHost

func WithHost(host string) Option

func WithPort

func WithPort(port int) Option

type Page

type Page struct {
	Tmpl        string
	Data        any
	RedirectURL string
	Err         error
}

func (*Page) ServeHTTP

func (p *Page) ServeHTTP(w http.ResponseWriter, r *http.Request)

type PageHandler

type PageHandler func(w http.ResponseWriter, r *http.Request) *Page

type RequestIDSetter

type RequestIDSetter interface {
	SetRequestID(id string)
}

type Todo

type Todo struct {
	ID     int64  `json:"id"`
	Title  string `json:"title"`
	Status string `json:"status"`
}

type TodoStore

type TodoStore interface {
	CreateTodo(ctx context.Context, params todostore.CreateTodoParams) (int64, error)
	UpdateTodo(ctx context.Context, id int64, params todostore.UpdateTodoParams) error
	FindTodos(ctx context.Context, params todostore.FindTodosParams) ([]todostore.Todo, error)
	DeleteTodo(ctx context.Context, id int64) error
}

type UpdateTodoResponse

type UpdateTodoResponse struct {
	ID int64 `json:"id"`
}

type ViewTodoResponse

type ViewTodoResponse struct {
	Title string
	Todo
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳