util

package
v1.0.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTooManyParts = errors.New("ratelimiter string invalid: too many parts")

Functions

func GenerateID

func GenerateID(t string, l int) string

func GenerateKey

func GenerateKey(length int) string

func GeneratePhrase

func GeneratePhrase(length int) string

func Highlight

func Highlight(code string, extension string) (string, string, error)

Highlight uses Chroma to highlight code in documents.

func Logger

func Logger(next http.Handler) http.Handler

Logger uses zerolog to log information about each request (log level = INFO)

func ParseRatelimiterString

func ParseRatelimiterString(rl string) (int, time.Duration, error)

func RenderError

func RenderError(r *embed.FS, w http.ResponseWriter, status int, err error) error

RenderError renders errors to the client using an HTML template.

func ValidateBody

func ValidateBody(maxSize int, body CreateRequest) error

func WriteError

func WriteError(w http.ResponseWriter, status int, e error) error

WriteError writes an Error object (e) to an HTTP response writer (w)

func WriteJSON

func WriteJSON[R any](w http.ResponseWriter, status int, r R) error

WriteJSON writes a Request payload (p) to an HTTP response writer (w)

Types

type CreateRequest

type CreateRequest struct {
	Content string
}

func HandleBody

func HandleBody(maxSize int, r *http.Request) (CreateRequest, error)

HandleBody figures out whether a incoming request is in JSON or multipart/form-data and decodes it appropriately

type DocumentResponse

type DocumentResponse struct {
	ID        string `json:"id,omitempty"`         // The document ID.
	Content   string `json:"content,omitempty"`    // The document content.
	CreatedAt int64  `json:"created_at,omitempty"` // The Unix timestamp of when the document was inserted.
	UpdatedAt int64  `json:"updated_at,omitempty"` // The Unix timestamp of when the document was last modified.
	Exists    bool   `json:"exists,omitempty"`     // Whether the document does or does not exist.
}

DocumentResponse is a document object

Jump to

Keyboard shortcuts

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