app

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: MIT Imports: 43 Imported by: 2

Documentation

Index

Constants

View Source
const HTTPInKey = "input"

Variables

View Source
var (
	ErrServiceNotFound = errors.New("service not found")
)

Functions

func BootService

func BootService(bootstrapper func(a App) error)

func RegisterService

func RegisterService(registrar func(a App) error)

Types

type App

type App interface {
	ServiceRegistrar
	AppCore
}

func Get

func Get() App

Get returns the single instance of the app

type AppCore

type AppCore interface {
	Config() config.Configuration
	Router() Router
	RunningInConsole() bool
	AddCommands(commands []Command)
}

type AppEngine

type AppEngine interface {
	Bootstrapper
	ServiceRegistrar
	AppCore
}

func Configure

func Configure(optFuncs ...OptFunc) AppEngine

type Application

type Application struct {
	//*container.Container
	Services *ServiceContainer
	// contains filtered or unexported fields
}

Application is the main application

func (*Application) AddCommands

func (a *Application) AddCommands(commands []Command)

func (*Application) AddService

func (a *Application) AddService(serviceType interface{})

AddService is a helper method to easily add a service

func (*Application) Config

func (a *Application) Config() config.Configuration

func (*Application) HandleSignals

func (a *Application) HandleSignals(srv *http.Server)

func (*Application) Router

func (a *Application) Router() Router

func (*Application) Run

func (a *Application) Run()

func (*Application) RunningInConsole

func (a *Application) RunningInConsole() bool

func (*Application) Service

func (a *Application) Service(serviceType interface{}) error

Service is a helper method to easily get a service

func (*Application) WithCommands

func (a *Application) WithCommands(commands []Command) Bootstrapper

WithCommands register the commands

func (*Application) WithConfig

func (a *Application) WithConfig(c config.M) Bootstrapper

WithConfig sets the config map to the current config instance

func (*Application) WithRoutes

func (a *Application) WithRoutes(routeCallback RouteCallback) Bootstrapper

WithRoutes calls the provided callback and registers the routes

type BaseInput

type BaseInput struct {
	App       App
	Ctx       *Context
	Validator *Validator
}

type Bootstrapper

type Bootstrapper interface {
	WithConfig(c config.M) Bootstrapper
	WithCommands(commands []Command) Bootstrapper
	WithRoutes(routeCallback RouteCallback) Bootstrapper
	Run()
}

type Command

type Command func(a App) *cobra.Command

type Context

type Context struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*Context) Alert

func (c *Context) Alert(typ string, message string) *res.AlertMessage

func (*Context) App

func (c *Context) App() App

func (*Context) AuthUser

func (c *Context) AuthUser() interface{}

func (*Context) Back

func (c *Context) Back() error

func (*Context) BadRequest

func (c *Context) BadRequest(err error) error

func (*Context) Body

func (c *Context) Body() (map[string][]string, error)

func (*Context) Cookie

func (c *Context) Cookie(name string) *http.Cookie

func (*Context) DecodeJSON

func (c *Context) DecodeJSON(v interface{}) error

func (*Context) Download

func (c *Context) Download(path string, filename string) error

func (*Context) Error

func (c *Context) Error(status int, err error) error

func (*Context) File

func (c *Context) File(path string, headers ...map[string][]string) error

func (*Context) Forbidden

func (c *Context) Forbidden(err error) error

func (*Context) Form

func (c *Context) Form() (map[string][]string, error)

func (*Context) FormFile

func (c *Context) FormFile(key string) (multipart.File, *multipart.FileHeader, error)

func (*Context) Get

func (c *Context) Get(key string) any

func (*Context) GetHeader

func (c *Context) GetHeader(key string) string

func (*Context) GetInput

func (c *Context) GetInput() any

func (*Context) GetSession

func (c *Context) GetSession(key string) any

func (*Context) GetSessionString

func (c *Context) GetSessionString(key string) string

func (*Context) HTML

func (c *Context) HTML(body []byte) error

func (*Context) HasFile

func (c *Context) HasFile(key string) bool

func (*Context) HasFormURLEncodedRequest

func (c *Context) HasFormURLEncodedRequest() bool

func (*Context) HasMultiPartRequest

func (c *Context) HasMultiPartRequest() bool

func (*Context) Inertia

func (c *Context) Inertia(filePath string, props map[string]any) error

func (*Context) Input

func (c *Context) Input(inputStruct any) any

func (*Context) InternalServerError

func (c *Context) InternalServerError(err error) error

func (*Context) IsInertiaRequest

func (c *Context) IsInertiaRequest() bool

func (*Context) IsReading

func (c *Context) IsReading() bool

func (*Context) JSON

func (c *Context) JSON(body M) error

func (*Context) Next

func (c *Context) Next() error

func (*Context) NoContent

func (c *Context) NoContent() error

func (*Context) NotFound

func (c *Context) NotFound(err error) error

func (*Context) PageExpired

func (c *Context) PageExpired() error

func (*Context) Param

func (c *Context) Param(key string) string

func (*Context) ParseInput

func (c *Context) ParseInput(inputStruct any) error

func (*Context) PopSession

func (c *Context) PopSession(key string) any

func (*Context) PopSessionString

func (c *Context) PopSessionString(key string) string

func (*Context) PutSession

func (c *Context) PutSession(key string, value any) *Context

func (*Context) Query

func (c *Context) Query(key string) string

func (*Context) Redirect

func (c *Context) Redirect(url string) error

func (*Context) Referer

func (c *Context) Referer() string

func (*Context) Render

func (c *Context) Render(tmplPath string, data *res.TemplateData) error

func (*Context) Request

func (c *Context) Request() *http.Request

func (*Context) RequestContext

func (c *Context) RequestContext() context.Context

func (*Context) Respond

func (c *Context) Respond(r *R) error

func (*Context) ResponseWriter

func (c *Context) ResponseWriter() http.ResponseWriter

func (*Context) Set

func (c *Context) Set(key string, value interface{})

func (*Context) SetCookie

func (c *Context) SetCookie(name string, value string, maxAge int, path string, domain string, secure bool, httpOnly bool)

SetCookie sets a cookie on the response writer Example: // c.SetCookie("jwt", token, 60*60*24*7, "/", "", false, true)

func (*Context) SetHeader

func (c *Context) SetHeader(key string, value string)

func (*Context) SetInput

func (c *Context) SetInput(inputStruct any) error

func (*Context) SetRequest

func (c *Context) SetRequest(r *http.Request)

func (*Context) Status

func (c *Context) Status(status int) *Context

func (*Context) StorageFile

func (c *Context) StorageFile(path string, headers ...map[string][]string) error

func (*Context) Templ

func (c *Context) Templ(component templ.Component) error

func (*Context) Text

func (c *Context) Text(body []byte) error

func (*Context) Unauthorized

func (c *Context) Unauthorized(err error) error

func (*Context) Upload

func (c *Context) Upload(uploadedFileName string, dir string, filename ...string) (*os.File, error)

func (*Context) Validate

func (c *Context) Validate(body req.Validator) error

func (*Context) ValidationError

func (c *Context) ValidationError(err error) error

func (*Context) WantsHTML

func (c *Context) WantsHTML() bool

func (*Context) WantsJSON

func (c *Context) WantsJSON() bool

func (*Context) With

func (c *Context) With(key string, message string) *Context

func (*Context) WithData

func (c *Context) WithData(data map[string]any) *Context

func (*Context) WithError

func (c *Context) WithError(message string) *Context

func (*Context) WithErrors

func (c *Context) WithErrors(errors shared.ValidationErrors) *Context

func (*Context) WithInfo

func (c *Context) WithInfo(message string) *Context

func (*Context) WithInput

func (c *Context) WithInput() *Context

func (*Context) WithSuccess

func (c *Context) WithSuccess(message string) *Context

func (*Context) WithWarning

func (c *Context) WithWarning(message string) *Context

type FileInput

type FileInput struct {
	*httpin.File
}

type Group

type Group struct {
	// contains filtered or unexported fields
}

func (*Group) Delete

func (g *Group) Delete(pattern string, handlers ...Handler) *Route

func (*Group) Get

func (g *Group) Get(pattern string, handlers ...Handler) *Route

func (*Group) Group

func (g *Group) Group(prefix string) *Group

func (*Group) Patch

func (g *Group) Patch(pattern string, handlers ...Handler) *Route

func (*Group) Post

func (g *Group) Post(pattern string, handlers ...Handler) *Route

func (*Group) Put

func (g *Group) Put(pattern string, handlers ...Handler) *Route

func (*Group) UseAfter

func (g *Group) UseAfter(handlers ...Handler)

func (*Group) UseBefore

func (g *Group) UseBefore(handlers ...Handler)

type HTTPMiddleware

type HTTPMiddleware func(http.Handler) http.Handler

type HTTPRouter

type HTTPRouter struct {
	// contains filtered or unexported fields
}

func (*HTTPRouter) Connect

func (r *HTTPRouter) Connect(pattern string, handlers ...Handler) *Route

func (*HTTPRouter) Delete

func (r *HTTPRouter) Delete(pattern string, handlers ...Handler) *Route

func (*HTTPRouter) Get

func (r *HTTPRouter) Get(pattern string, handlers ...Handler) *Route

func (*HTTPRouter) Group

func (r *HTTPRouter) Group(prefix string) *Group

func (*HTTPRouter) Handle

func (r *HTTPRouter) Handle(pattern string, handler http.Handler)

func (*HTTPRouter) HandleFunc

func (r *HTTPRouter) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))

func (*HTTPRouter) HasRoute

func (r *HTTPRouter) HasRoute(method string, pattern string) bool

func (*HTTPRouter) Head

func (r *HTTPRouter) Head(pattern string, handlers ...Handler) *Route

func (*HTTPRouter) Options

func (r *HTTPRouter) Options(pattern string, handlers ...Handler) *Route

func (*HTTPRouter) Patch

func (r *HTTPRouter) Patch(pattern string, handlers ...Handler) *Route

func (*HTTPRouter) Post

func (r *HTTPRouter) Post(pattern string, handlers ...Handler) *Route

func (*HTTPRouter) Put

func (r *HTTPRouter) Put(pattern string, handlers ...Handler) *Route

func (*HTTPRouter) ServeHTTP

func (r *HTTPRouter) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*HTTPRouter) Trace

func (r *HTTPRouter) Trace(pattern string, handlers ...Handler) *Route

func (*HTTPRouter) Use

func (r *HTTPRouter) Use(middlewares ...HTTPMiddleware)

Use adds one or more standard net/http middleware to the router

func (*HTTPRouter) UseAfter

func (r *HTTPRouter) UseAfter(handlers ...Handler)

func (*HTTPRouter) UseBefore

func (r *HTTPRouter) UseBefore(handlers ...Handler)

type Handler

type Handler func(c *Context) error

type M

type M map[string]any

func (M) Error

func (m M) Error() string

Error returns a string representation of the JSON-encoded map.

type Middleware

type Middleware func(next Handler) Handler

func Input

func Input(inputStruct any, opts ...core.Option) Middleware

type OptFunc

type OptFunc func(opts *Options)

func WithCommands

func WithCommands(commands []Command) OptFunc

func WithConfig

func WithConfig(config config.M) OptFunc

func WithRoutes

func WithRoutes(routes RouteCallback) OptFunc

type Options

type Options struct {
	Config   config.M
	Commands []Command
	Routes   RouteCallback
}

type Publishable

type Publishable struct {
	FilePath string
	Content  []byte
	Tag      string
}

func (*Publishable) Publish

func (p *Publishable) Publish() error

type R

type R struct {
	Status       int
	Payload      M
	TemplateView string
	TemplView    string
	InertiaView  string
	RedirectTo   string
}

type Route

type Route struct {
	Method           string
	Path             string
	Handlers         []Handler
	BeforeMiddleware []Handler
	AfterMiddleware  []Handler
	// contains filtered or unexported fields
}

func (*Route) UseAfter

func (r *Route) UseAfter(handlers ...Handler) *Route

func (*Route) UseBefore

func (r *Route) UseBefore(handlers ...Handler) *Route

type RouteCallback

type RouteCallback func(r Router)

type Router

type Router interface {
	Group(prefix string) *Group
	UseBefore(handlers ...Handler)
	UseAfter(handlers ...Handler)
	HasRoute(method string, pattern string) bool
	Handle(pattern string, handler http.Handler)
	HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
	Get(pattern string, handlers ...Handler) *Route
	Post(pattern string, handlers ...Handler) *Route
	Put(pattern string, handlers ...Handler) *Route
	Patch(pattern string, handlers ...Handler) *Route
	Delete(pattern string, handlers ...Handler) *Route
	Connect(pattern string, handlers ...Handler) *Route
	Head(pattern string, handlers ...Handler) *Route
	Options(pattern string, handlers ...Handler) *Route
	Trace(pattern string, handlers ...Handler) *Route
	Use(middlewares ...HTTPMiddleware)
}

type ServiceContainer

type ServiceContainer struct {
	// contains filtered or unexported fields
}

ServiceContainer holds all the application's dependencies

func (*ServiceContainer) Add

func (sc *ServiceContainer) Add(service interface{})

Add adds a service to the container

func (*ServiceContainer) Get

func (sc *ServiceContainer) Get(service interface{}) error

Get retrieves a service from the container and populates the provided pointer or pointer to pointer

type ServiceRegistrar

type ServiceRegistrar interface {
	Service(serviceType interface{}) error
	AddService(serviceType interface{})
}

type VField

type VField struct {
	// contains filtered or unexported fields
}

func (*VField) ActiveURL

func (f *VField) ActiveURL() *VField

ActiveURL checks if the URL is active and reachable

func (*VField) AfterDate

func (f *VField) AfterDate(afterDate time.Time) *VField

AfterDate checks if the date is after the specified date

func (*VField) Alpha

func (f *VField) Alpha() *VField

Alpha checks if the value contains only alphabetic characters

func (*VField) AlphaDash

func (f *VField) AlphaDash() *VField

AlphaDash checks if the string contains only alpha-numeric characters, dashes, or underscores

func (*VField) AlphaNumeric

func (f *VField) AlphaNumeric() *VField

AlphaNumeric checks if the value contains only alphanumeric characters

func (*VField) Ascii

func (f *VField) Ascii() *VField

Ascii checks if the string contains only ASCII characters

func (*VField) BeforeDate

func (f *VField) BeforeDate(beforeDate time.Time) *VField

BeforeDate checks if the date is before the specified date

func (*VField) Between

func (f *VField) Between(min, max int) *VField

Between checks if the value is between min and max (inclusive)

func (*VField) Boolean

func (f *VField) Boolean() *VField

Boolean checks if the value is a valid boolean

func (*VField) Contains

func (f *VField) Contains(substring string) *VField

Contains checks if the string contains the specified substring

func (*VField) Custom

func (f *VField) Custom(validateFunc func(v interface{}) (bool, string)) *VField

Custom allows defining a custom validation rule

func (*VField) Date

func (f *VField) Date(layout string) *VField

Date checks if the value is a valid date in the specified format

func (*VField) Dimensions

func (f *VField) Dimensions(width, height int) *VField

Dimensions checks if the image file has the specified dimensions

func (*VField) Distinct

func (f *VField) Distinct() *VField

Distinct checks if all elements in a slice are unique

func (*VField) Email

func (f *VField) Email() *VField

Email checks if the value is a valid email address

func (*VField) EndsWith

func (f *VField) EndsWith(suffix string) *VField

EndsWith checks if the string ends with the specified substring

func (*VField) Equals

func (f *VField) Equals(value interface{}) *VField

Equals checks if the value is equal to the provided value

func (*VField) Filled

func (f *VField) Filled() *VField

Filled checks if the value is not empty (for strings, slices, maps, and pointers)

func (*VField) ForEach

func (f *VField) ForEach(rules ...func(*VField) *VField) *VField

ForEach applies validation rules to each item in an array

func (*VField) HexColor

func (f *VField) HexColor() *VField

HexColor checks if the string is a valid hexadecimal color code

func (*VField) IP

func (f *VField) IP() *VField

IP checks if the value is a valid IP address (v4 or v6)

func (*VField) In

func (f *VField) In(validValues []string) *VField

In checks if the value is in the given slice of valid values

func (*VField) JSON

func (f *VField) JSON() *VField

JSON checks if the value is a valid JSON string

func (*VField) MacAddress

func (f *VField) MacAddress() *VField

MacAddress checks if the string is a valid MAC address

func (*VField) Max

func (f *VField) Max(max int) *VField

Max checks if the value is less than or equal to the maximum

func (*VField) MimeTypes

func (f *VField) MimeTypes(allowedTypes []string) *VField

MimeTypes checks if the file has one of the specified MIME types

func (*VField) Min

func (f *VField) Min(min int) *VField

Min checks if the value is greater than or equal to the minimum

func (*VField) Name

func (f *VField) Name() string

func (*VField) Numeric

func (f *VField) Numeric() *VField

Numeric checks if the value contains only numeric characters

func (*VField) Regex

func (f *VField) Regex(pattern string) *VField

Regex checks if the value matches the given regular expression

func (*VField) Required

func (f *VField) Required() *VField

Required checks if the value is not empty

func (*VField) SetValue

func (f *VField) SetValue(value interface{}) *VField

func (*VField) StartsWith

func (f *VField) StartsWith(prefix string) *VField

StartsWith checks if the string starts with the specified substring

func (*VField) Timezone

func (f *VField) Timezone() *VField

Timezone checks if the value is a valid timezone

func (*VField) ULID

func (f *VField) ULID() *VField

ULID checks if the string is a valid ULID

func (*VField) URL

func (f *VField) URL() *VField

URL checks if the value is a valid URL

func (*VField) UUID

func (f *VField) UUID() *VField

UUID checks if the value is a valid UUID

func (*VField) Unique

func (f *VField) Unique(table string, column string, whereClauses ...map[string]interface{}) *VField

func (*VField) Value

func (f *VField) Value() interface{}

type Validator

type Validator struct {
	App
	Errors shared.ValidationErrors
}

func NewValidator

func NewValidator(app App) *Validator

func (*Validator) AddError

func (v *Validator) AddError(field, message string)

func (*Validator) ErrorsJSON

func (v *Validator) ErrorsJSON() map[string][]string

func (*Validator) Field

func (v *Validator) Field(name string, value interface{}) *VField

Field creates a new Field instance for chaining validation rules

func (*Validator) IsValid

func (v *Validator) IsValid() bool

func (*Validator) Validate

func (v *Validator) Validate() error

Jump to

Keyboard shortcuts

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