backend

package
v0.0.0-...-1c0d726 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: AGPL-3.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Argon2Memory    = 64 * 1024
	Argon2Time      = 2
	Argon2Threads   = 4
	Argon2KeyLength = 32
)

Variables

View Source
var JSONResponseOK = JSONResponse{Status: "ok"}

Functions

func AccountIDFromCtx

func AccountIDFromCtx(ctx context.Context) (uuid.UUID, bool)

func CheckPasswordHash

func CheckPasswordHash(password []byte, passwordHash string) (bool, error)

func CtxWithAccountID

func CtxWithAccountID(parent context.Context, accountID uuid.UUID) context.Context

func CtxWithID

func CtxWithID(parent context.Context, id uuid.UUID) context.Context

func CtxWithSessionID

func CtxWithSessionID(parent context.Context, accountID uuid.UUID) context.Context

func IDFromCtx

func IDFromCtx(ctx context.Context) (uuid.UUID, bool)

func JSONError

func JSONError(rw http.ResponseWriter, r *http.Request, msg string, code int)

func NewPasswordHash

func NewPasswordHash(password, salt []byte) string

func RequireRequestBody

func RequireRequestBody(next http.Handler) http.Handler

func SessionIDFromCtx

func SessionIDFromCtx(ctx context.Context) (uuid.UUID, bool)

func WithUUIDFromURL

func WithUUIDFromURL(next http.Handler) http.Handler

Types

type AccountGetResponse

type AccountGetResponse struct {
	JSONResponse
	Account models.Account `json:"account"`
}

type AccountPutRequest

type AccountPutRequest struct {
	Username *string `json:"username"`
	Email    *string `json:"email"`
	Password string  `json:"password"`
}

type AccountPutResponse

type AccountPutResponse struct {
	JSONResponse
	Account models.Account `json:"account"`
}

type FilePutResponse

type FilePutResponse struct {
	JSONResponse
	Files []*models.File
}

type HTTPError

type HTTPError struct {
	StatusCode int
	Err        error
}

func (HTTPError) Error

func (err HTTPError) Error() string

func (HTTPError) Unwrap

func (err HTTPError) Unwrap() error

type JSONResponse

type JSONResponse struct {
	Status  string `json:"status"`
	Message string `json:"message,omitzero"`
}

type PostDeleteResponse

type PostDeleteResponse struct {
	JSONResponse
}

type PostGetResponse

type PostGetResponse struct {
	JSONResponse
	Post models.Post `json:"post"`
}

type PostPostRequest

type PostPostRequest struct {
	Subject *string     `json:"subject"`
	Content string      `json:"content"`
	Tags    []string    `json:"tags"`
	FileIDs []uuid.UUID `json:"file_ids"`
}

type PostPostResponse

type PostPostResponse struct {
	JSONResponse
	Post models.Post `json:"post"`
}

type PostPutRequest

type PostPutRequest struct {
	ProfileID uuid.UUID   `json:"profile_id"`
	ReplyToID *uuid.UUID  `json:"reply_to_id"`
	Subject   *string     `json:"subject"`
	Content   string      `json:"content"`
	Tags      []string    `json:"tags"`
	PollID    *uuid.UUID  `json:"poll_id"`
	GroupIDs  []uuid.UUID `json:"group_ids"`
	FileIDs   []uuid.UUID `json:"file_ids"`
	PublishAt *time.Time  `json:"publish_at"`
	DeleteAt  *time.Time  `json:"delete_at"`
}

type PostPutResponse

type PostPutResponse struct {
	JSONResponse
	Post              *models.Post `json:"post,omitempty"`
	PublishScheduleID *uuid.UUID   `json:"publish_schedule_id,omitempty"`
	DeleteScheduleID  *uuid.UUID   `json:"delete_schedule_id,omitempty"`
}

type ProfileGetResponse

type ProfileGetResponse struct {
	JSONResponse
	Profile models.Profile `json:"profile"`
}

type ProfilePutRequest

type ProfilePutRequest struct {
	Name        string `json:"name"`
	DisplayName string `json:"display_name"`
	Description string `json:"description"`
}

type ProfilePutResponse

type ProfilePutResponse struct {
	JSONResponse
	Profile models.Profile `json:"profile"`
}

type Server

type Server struct {
	Config *config.Config
	// contains filtered or unexported fields
}

func NewServer

func NewServer(cfg *config.Config) (*Server, error)

func (*Server) APIv1Router

func (server *Server) APIv1Router(r chi.Router)

func (*Server) AccountGet

func (server *Server) AccountGet(rw http.ResponseWriter, r *http.Request)

func (*Server) AccountHead

func (server *Server) AccountHead(rw http.ResponseWriter, r *http.Request)

func (*Server) AccountPut

func (server *Server) AccountPut(rw http.ResponseWriter, r *http.Request)

func (*Server) AutoCleanupExpiredSessions

func (server *Server) AutoCleanupExpiredSessions(every time.Duration)

func (*Server) Close

func (server *Server) Close()

func (*Server) FilePut

func (server *Server) FilePut(rw http.ResponseWriter, r *http.Request)

func (*Server) GetMigrationStatus

func (server *Server) GetMigrationStatus(ctx context.Context) (applied, unapplied int, err error)

func (*Server) Migrate

func (server *Server) Migrate(ctx context.Context) (applied int, err error)

func (*Server) PostDelete

func (server *Server) PostDelete(rw http.ResponseWriter, r *http.Request)

func (*Server) PostGet

func (server *Server) PostGet(rw http.ResponseWriter, r *http.Request)

func (*Server) PostPost

func (server *Server) PostPost(rw http.ResponseWriter, r *http.Request)

func (*Server) PostPut

func (server *Server) PostPut(rw http.ResponseWriter, r *http.Request)

func (*Server) ProfileGet

func (server *Server) ProfileGet(rw http.ResponseWriter, r *http.Request)

func (*Server) ProfileHead

func (server *Server) ProfileHead(rw http.ResponseWriter, r *http.Request)

func (*Server) ProfilePut

func (server *Server) ProfilePut(rw http.ResponseWriter, r *http.Request)

func (*Server) SessionDelete

func (server *Server) SessionDelete(rw http.ResponseWriter, r *http.Request)

func (*Server) SessionPut

func (server *Server) SessionPut(rw http.ResponseWriter, r *http.Request)

func (*Server) SetLocalInstance

func (server *Server) SetLocalInstance(create bool) (created bool, err error)

func (*Server) Setup

func (server *Server) Setup(create bool) error

func (*Server) StartScheduler

func (server *Server) StartScheduler() error

func (*Server) Transaction

func (server *Server) Transaction(fn func(ctx context.Context, tx bun.Tx) error) error

func (*Server) ValidateSession

func (server *Server) ValidateSession(next http.Handler) http.Handler

func (*Server) View

func (server *Server) View(fn func(ctx context.Context, tx bun.Tx) error) error

type SessionPutRequest

type SessionPutRequest struct {
	Username *string `json:"username"`
	Email    *string `json:"email"`
	Password string  `json:"password"`
}

type SessionPutResponse

type SessionPutResponse struct {
	JSONResponse
	Session models.AccountSession `json:"session"`
	Token   string                `json:"token"`
}

Jump to

Keyboard shortcuts

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