api

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorPersistenceRead = HttpError{
	Status:      http.StatusInternalServerError,
	Description: "Problem reading from persistence layer",
}
View Source
var ErrorPersistenceWrite = HttpError{
	Status:      http.StatusInternalServerError,
	Description: "Problem writing to persistence layer",
}
View Source
var ErrorPostForbidden = HttpError{
	Status:      http.StatusForbidden,
	Description: "You are not authorized to perform this action for this post",
}
View Source
var ErrorPostNotFound = HttpError{
	Status:      http.StatusNotFound,
	Description: "Post not found",
}

Functions

func GetCategoryPersistence added in v0.0.2

func GetCategoryPersistence(ctx context.Context) persistence.Persistencer[Category]

GetCategoryPersistence from context (where categories are stored)

func GetPostPersistence added in v0.0.2

func GetPostPersistence(ctx context.Context) persistence.Persistencer[Post]

GetPostPersistence from context (where posts are stored)

func HandleDeletePost added in v0.0.2

func HandleDeletePost(ctx context.Context, w http.ResponseWriter, r *http.Request) error

func HandleMethodNotAllowed added in v0.0.2

func HandleMethodNotAllowed(ctx context.Context, r *http.Request)

func HandleNotFound

func HandleNotFound(w http.ResponseWriter, r *http.Request)

func HandleRenderHome added in v0.0.2

func HandleRenderHome(w http.ResponseWriter, r *http.Request) error

func HandleRenderPost added in v0.0.2

func HandleRenderPost(w http.ResponseWriter, r *http.Request) error

func HandleSitemap added in v0.0.2

func HandleSitemap(w http.ResponseWriter, ctx context.Context) error

func InterceptorAccessLog added in v0.0.2

func InterceptorAccessLog(next box.H) box.H

func NewApi

func NewApi(
	version, staticsDir string,
	postPersistencer persistence.Persistencer[Post],
	categoryPersistencer persistence.Persistencer[Category],
	log *slog.Logger,
) http.Handler

func PrettyError added in v0.0.2

func PrettyError(next box.H) box.H

Types

type Category added in v0.0.2

type Category struct {
	Id string `json:"id"`

	Name string `json:"name"`

	CreationTime     time.Time `json:"creation_time"`
	ModificationTime time.Time `json:"modification_time"`
}

func HandleCreateCategory added in v0.0.2

func HandleCreateCategory(input *CreateCategoryRequest, w http.ResponseWriter, ctx context.Context) (*Category, error)

func (*Category) Validate added in v0.0.2

func (c *Category) Validate() error

type CreateCategoryRequest added in v0.0.2

type CreateCategoryRequest struct {
	Name string `json:"name"`
}

type CreatePostRequest added in v0.0.2

type CreatePostRequest struct {
	Title string `json:"title"`
	Body  string `json:"body"`
}

type HttpError added in v0.0.2

type HttpError struct {
	Status      int    `json:"-"`
	Title       string `json:"title"`
	Description string `json:"description"`
}

func (HttpError) Error added in v0.0.2

func (h HttpError) Error() string

type ModifyPostRequest added in v0.0.2

type ModifyPostRequest struct {
	Title *string `json:"title"`
	Body  *string `json:"body"`
}

type Post added in v0.0.2

type Post struct {
	Id string `json:"id"`

	Author auth.User `json:"author"`

	Title string `json:"title"`
	Body  string `json:"body"`

	CreationTime     time.Time `json:"creation_time"`
	ModificationTime time.Time `json:"modification_time"`
}

func HandleCreatePost added in v0.0.2

func HandleCreatePost(input *CreatePostRequest, w http.ResponseWriter, ctx context.Context) (*Post, error)

func HandleGetPost added in v0.0.2

func HandleGetPost(ctx context.Context, r *http.Request) (*Post, error)

func HandleListPosts added in v0.0.2

func HandleListPosts(w http.ResponseWriter, r *http.Request) ([]Post, error)

func HandleModifyPost added in v0.0.2

func HandleModifyPost(ctx context.Context, r *http.Request, input *ModifyPostRequest) (*Post, error)

func (*Post) Validate added in v0.0.2

func (e *Post) Validate() error

Jump to

Keyboard shortcuts

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