Documentation ¶
Index ¶
- func NewApp(name string, strictSlash bool, cr Config) *app
- func NewConfig(fileName, configPath, envPrefix, envSeparatorChar string) *configReader
- func NewContext(ctx context.Context, ll logger.LogLevel) *defaultContext
- func NewError(httpCode int, errCode string, errMessage string) *goframeError
- func NewHTTPService(name string) *httpService
- func NewRouter(strictSlash bool) *defaultRouter
- func NewServerContext(ctx context.Context, ll logger.LogLevel, res http.ResponseWriter, ...) *defaultServerContext
- type BackgroundService
- type Config
- type Context
- type HTTPService
- type Handler
- type MiddlewareFunc
- type MiddlewareStack
- type ResponseWriter
- type Router
- type ServerContext
- type Service
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewApp ¶
NewApp returns an instance of app. app is where it all happens!
strictSlash defines the trailing slash behavior for new routes. When true, if the route path is "/path/", accessing "/path" will perform a redirect to the former and vice versa. In other words, your application will always see the path as specified in the route.
Config is a nullable field; if null it uses a default configReader = NewConfigReader(app.name, "./configs/", app.name, "_")
func NewConfig ¶ added in v0.1.4
func NewConfig(fileName, configPath, envPrefix, envSeparatorChar string) *configReader
NewConfig is used to create a new instance of Config Config reads the configs from config files or env variables.
config := NewConfig(fileName, configPath, envPrefix, envSeparatorChar)
func NewContext ¶
NewContext is used to get an instance of the default implementation of goframe.Context
func NewHTTPService ¶
func NewHTTPService(name string) *httpService
NewHTTPService creates a goframe HTTP Service; where `name` would be the default prefix of the Router.
func NewRouter ¶
func NewRouter(strictSlash bool) *defaultRouter
NewRouter returns an instance of an implementation of Router interface.
func NewServerContext ¶
func NewServerContext(ctx context.Context, ll logger.LogLevel, res http.ResponseWriter, req *http.Request, ) *defaultServerContext
NewServerContext is used to get an instance of the default implementation of goframe.ServerContext
Types ¶
type BackgroundService ¶
BackgroundService is a goframe Service used for running background workers.
type Config ¶ added in v0.1.4
type Config interface { // GetString gets a string config GetString(key string) string // GetBool gets a boolean config GetBool(key string) bool // GetInt gets an integer config GetInt(key string) int // GetStringSlice gets a string slice ([]string) config GetStringSlice(key string) []string // GetIntSlice gets an integer slice ([]int) config GetIntSlice(key string) []int // GetStringMap gets a string Map (map[string]interface{}) config GetStringMap(key string) map[string]interface{} }
Config is used to read the configs from config files or env variables.
config := NewConfig(fileName, configPath, envPrefix, envSeparatorChar)
type Context ¶
type Context interface { context.Context Logger() *logger.Logger Set(string, interface{}) Get(interface{}) interface{} }
Context is goframe implementation of context. This is to be used across goframe
type HTTPService ¶
type HTTPService interface { Service // CustomPrefix replaces the default path prefix by the // custom one passed in. The routes on the service // would have the `Service Name` as a default prefix. CustomPrefix(string) Route(path, httpMethod string, handler Handler) // Use the specified Middleware for the `HTTPService`. // The specified middleware will be inherited by any calls // that are made on the HTTPService. Use(mw ...MiddlewareFunc) // Group creates a new `HTTPService` that inherits from it's parent `HTTPService`. // This is useful for creating groups of end-points that need to share // common functionality, like middleware. /* g := a.Group() g.Use(AuthorizeAPIMiddleware) */ NewGroup() *httpService // contains filtered or unexported methods }
HTTPService is a goframe Service used for running a http server.
type Handler ¶ added in v0.1.5
type Handler func(ServerContext) error
Handler is the basis for a HTTPService Endpoint. A Handler will be given a ServerContext interface that represents the given request/response. It is the responsibility of the Handler to handle the request/response correctly. This could mean rendering a template, JSON, etc... or it could mean returning an error.
func (c ServerContext) error { return c.Response().GenericJSON("Hello World!") }
type MiddlewareFunc ¶
MiddlewareFunc defines the interface for a piece of goframe Middleware.
func DoSomething(next Handler) Handler { return func(c ServerContext) error { // do something before calling the next handler err := next(c) // do something after call the handler return err } }
type MiddlewareStack ¶
type MiddlewareStack struct {
// contains filtered or unexported fields
}
MiddlewareStack manages the middleware stack for an app/Group.
func (*MiddlewareStack) Use ¶
func (ms *MiddlewareStack) Use(mw ...MiddlewareFunc)
Use the specified Middleware for the `HTTPService`. The specified middleware will be inherited by any calls that are made on the HTTPService.
type ResponseWriter ¶
type ResponseWriter interface { SuccessJSON(httpStatusCode int, data interface{}, message string) error ErrorJSON(err error) error Generic(httpStatusCode int, data []byte) error }
ResponseWriter interface is used by a goframe Handler to construct an HTTP response.
A ResponseWriter may not be used after the Router.ServeHTTP method has returned.
type Router ¶
type Router interface { Handle(method string, path string, handler http.Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) }
Router registers routes to be matched and dispatches a handler.
type ServerContext ¶
type ServerContext interface { Context // Request returns *http.Request Request() *http.Request // Response returns goframe.ResponseWriter Response() ResponseWriter // Params returns all of the parameters for the request, // including both named params and query string parameters. Params() url.Values // Param returns a param, either named or query string, // based on the key. Param(key string) string }
ServerContext is a goframe Context with more specific context related to a http server.
type Service ¶
type Service interface { // Name is the name of the service; // this would be the prefix in case of HTTPService Name() string // SetInCtx sets required data into the service context; // It can be used to pass env elements like connections, configs, etc. SetInCtx(key string, value interface{}) // contains filtered or unexported methods }
Service is the basic unit of a goframe app. It forms the base of any services like * HTTPService for a http server * BackgroundService for running workers