Documentation
¶
Overview ¶
Package rady provides framework for web developer
The Rady Framework is a spring like web framework base on echo-framework
Index ¶
- Constants
- Variables
- func CheckComponents(field reflect.StructField) bool
- func CheckConfiguration(field reflect.StructField) bool
- func CheckController(field reflect.StructField) bool
- func CheckEntities(field reflect.StructField) bool
- func CheckFieldPtr(fieldType reflect.Type) bool
- func CheckFilenameValid(Name string) bool
- func CheckMiddleware(field reflect.StructField) bool
- func CheckRouter(field reflect.StructField) bool
- func CheckStruct(fieldType reflect.Type) bool
- func CheckValues(field reflect.StructField) bool
- func ConfirmAddBeanMap(BeanMap map[reflect.Type]map[string]*Bean, fieldType reflect.Type, name string) bool
- func ConfirmBeanInMap(BeanMap map[reflect.Type]map[string]*Bean, fieldType reflect.Type, name string) bool
- func ConfirmSameTypeInMap(BeanMap map[reflect.Type]map[string]*Bean, fieldType reflect.Type) bool
- func ContainsField(Mother reflect.Type, field interface{}) bool
- func ContainsFields(Mother reflect.Type, Set map[reflect.Type]bool) bool
- func GetBeanName(Type reflect.Type, tag reflect.StructTag) string
- func GetDynamicPath(upper string) string
- func GetHttpMethodAndPath(Name string) (interface{}, string)
- func GetJSONFromAnyFile(path string, fileType string) (string, error)
- func GetNewPrefix(prefix string, path string) string
- func GetPathFromType(field reflect.StructField, Type interface{}) string
- func GetTagFromName(name string) reflect.StructTag
- func IsStringAllUpper(str string) bool
- func ParseHandlerName(Name string) (ok bool, method interface{}, path string)
- func SplitByUpper(raw string) []string
- type Application
- func (a *Application) CallFactory()
- func (a *Application) LoadBean(fieldType reflect.Type, fieldValue reflect.Value, tag reflect.StructTag) *Application
- func (a *Application) LoadBeanAndRecursion(fieldType reflect.Type)
- func (a *Application) LoadPrimeBean(fieldType reflect.Type, fieldValue reflect.Value, tag reflect.StructTag) bool
- func (a *Application) RecursivelyLoad(fieldType reflect.Type)
- func (a *Application) ReloadValues()
- func (a *Application) Run()
- type Bean
- type BootStrap
- type CONF
- type CONNECT
- type Component
- type Configuration
- type Context
- type Controller
- type CtrlBean
- type DELETE
- type Entities
- type FILE
- type GET
- type Group
- type HEAD
- type Handler
- type HandlerFunc
- type Logger
- type MdWareBean
- type Method
- type Middleware
- type MiddlewareFunc
- type OPTIONS
- type PATCH
- type POST
- type PUT
- type Parameter
- type Repository
- type Router
- type STATIC
- type Service
- type TRACE
- type ValueBean
Constants ¶
const COMPONENT = "component"
COMPONENT is a tag to mark a field as a Component
const CONFIGURATION = "configuration"
CONFIGURATION is a tag to mark a field as a Configuration
const CONTROLLER = "controller"
CONTROLLER is a tag to mark a field as a Controller
const ConnectStr = "Connect"
const DefaultPath = "./resources/application.conf"
DefaultPath is the path of config file for default
const DeleteStr = "Delete"
const ENTITIES = "entities"
ENTITIES is a tag to mark a field as a Entities
const GetStr = "Get"
const HANDLER = "handler"
HANDLER is a tag to mark a field as a Handler
const HeadStr = "Head"
const JSON = "json"
JSON is the suffix of json file
const MIDDLEWARE = "middleware"
MIDDLEWARE is a tag to mark a field as a Middleware
const OptionsStr = "Options"
const PatchStr = "Patch"
const PostStr = "Post"
const PutStr = "Put"
const REPOSITORY = "repository"
REPOSITORY is a tag to mark a field as a Repository
const ROUTER = "router"
ROUTER is a tag to mark a field as a Router
const SERVICE = "service"
SERVICE is a tag to mark a field as a Service
const TraceStr = "Trace"
const YAML = "yaml"
YAML is the suffix of yaml file
Variables ¶
var ( INT int64 UINT uint64 FLOAT float64 STRING string BOOL bool TIME time.Time ARRAY []gjson.Result MAP map[string]gjson.Result )
var ( IntPtrType = reflect.TypeOf(&INT) UintPtrType = reflect.TypeOf(&UINT) FloatPtrType = reflect.TypeOf(&FLOAT) StringPtrType = reflect.TypeOf(&STRING) BoolPtrType = reflect.TypeOf(&BOOL) TimePtrType = reflect.TypeOf(&TIME) ArrayPtrType = reflect.TypeOf(&ARRAY) MapPtrType = reflect.TypeOf(&MAP) )
var COMPONENTS = make(map[string]bool)
COMPONENTS is a map to check if a field is COMPONENT, SERVICE or REPOSITORY
var ComponentTypes = make(map[reflect.Type]bool)
ComponentTypes is a map to check if a struct is Component, Service, Repository or Parameter
var GJsonTypesSet = map[reflect.Type]bool{ IntPtrType: true, UintPtrType: true, FloatPtrType: true, StringPtrType: true, BoolPtrType: true, TimePtrType: true, ArrayPtrType: true, MapPtrType: true, }
var MethodToStr = map[interface{}]string{ GET{}: GetStr, POST{}: PostStr, PUT{}: PutStr, HEAD{}: HeadStr, DELETE{}: DeleteStr, CONNECT{}: ConnectStr, OPTIONS{}: OptionsStr, TRACE{}: TraceStr, PATCH{}: PatchStr, }
var MethodsTypeSet = make(map[reflect.Type]string)
Functions ¶
func CheckComponents ¶
func CheckComponents(field reflect.StructField) bool
CheckComponents return true when type in its tag is in COMPONENTS or ContainsFields(field.Type.Elem(), ComponentTypes)
func CheckConfiguration ¶
func CheckConfiguration(field reflect.StructField) bool
CheckConfiguration return true when type in its tag is CONFIGURATION or ContainsField(field.Type.Elem(), Configuration{})
func CheckController ¶
func CheckController(field reflect.StructField) bool
CheckController return true when type in its tag is CONTROLLER or ContainsField(field.Type.Elem(), Controller{})
func CheckEntities ¶
func CheckEntities(field reflect.StructField) bool
CheckEntities return true when type in its tag is entities or ContainsField(field.Type.Elem(), Entities{})
func CheckFieldPtr ¶
CheckFieldPtr return true when fieldType is kind of Ptr
func CheckFilenameValid ¶
func CheckMiddleware ¶
func CheckMiddleware(field reflect.StructField) bool
CheckMiddleware return true when type in its tag is MIDDLEWARE or ContainsField(field.Type.Elem(), Middleware{})
func CheckRouter ¶
func CheckRouter(field reflect.StructField) bool
CheckRouter return true when type in its tag is ROUTER or ContainsField(field.Type.Elem(), Router{})
func CheckStruct ¶
func CheckValues ¶
func CheckValues(field reflect.StructField) bool
func ConfirmAddBeanMap ¶
func ConfirmAddBeanMap(BeanMap map[reflect.Type]map[string]*Bean, fieldType reflect.Type, name string) bool
ConfirmAddBeanMap return true when BeanMap[fieldType] == nil or BeanMap[fieldType][name] doesn't exist
and this function will make a map if BeanMap[fieldType] == nil
func ConfirmBeanInMap ¶
func ConfirmBeanInMap(BeanMap map[reflect.Type]map[string]*Bean, fieldType reflect.Type, name string) bool
ConfirmBeanInMap return true when BeanMap[fieldType][name] exist
func ConfirmSameTypeInMap ¶
ConfirmSameTypeInMap return true when len(BeanMap[fieldType]) > 0
and this function will also make a map if BeanMap[fieldType] == nil, but return false
func ContainsField ¶
ContainsField return true when Mother has a child as same type as filed
func ContainsFields ¶
ContainsFields return true when Mother has a child with a type Set contains
func GetBeanName ¶
GetBeanName get name from tag or from Type
func GetDynamicPath ¶
func GetHttpMethodAndPath ¶
func GetJSONFromAnyFile ¶
GetJSONFromAnyFile can get json string from file
This function work well only when:
- fileType == "yaml" or (fileType != "json" and path end with ".yml" or ".yaml"), and content in file is yaml
- content in file is json
func GetNewPrefix ¶
func GetPathFromType ¶
func GetPathFromType(field reflect.StructField, Type interface{}) string
func GetTagFromName ¶
GetTagFromName generate tag from name
func IsStringAllUpper ¶
func ParseHandlerName ¶
func SplitByUpper ¶
Types ¶
type Application ¶
type Application struct { BootStrap Root interface{} BeanMap map[reflect.Type]map[string]*Bean BeanMethodMap map[reflect.Type]map[string]*Method ValueBeanMap map[string]*ValueBean FactoryToRecall map[*Method]bool CtrlBeanSlice []*CtrlBean MdWareBeanSlice []*MdWareBean Entities []reflect.Type Server *echo.Echo Logger *Logger ConfigFile string Addr *string `value:"rady.server.addr" default:":8081"` }
Application is the bootstrap of a Rhapsody app
Root is pointer of app for config, controller and handler registry ¶
BeanMap is map to find *Bean by `Type` and `Name`(when type is the same)
value in bean is Elem(), can get Addr() when set to other field
BeanMethodMap is map to find *Method by `Type` and `Name`(when type is the same)
Value in method can be call later to set value to other filed
ValueBeanMap is map to find / set value in config file, going to implement hot-reload
CtrlBeanSlice is slice to store controller ¶
MdWareBeanSlice is slice to store middleware ¶
Entities is slice to store type of entity ¶
Server is the echo server ¶
Logger is the global logger ¶
ConfigFile is the string json value of config file
func CreateApplication ¶
func CreateApplication(root interface{}) *Application
CreateApplication can initial application with root
if root is not kinds of Ptr, there will be an error
func (*Application) CallFactory ¶
func (a *Application) CallFactory()
func (*Application) LoadBean ¶
func (a *Application) LoadBean(fieldType reflect.Type, fieldValue reflect.Value, tag reflect.StructTag) *Application
LoadBean can load normal bean
normal bean can have a name, only if there is a prime bean with same name and type, and this method will do nothing
if a normal bean doesn't a name
there is only one loaded bean with the same type, this method do nothing
there are more than one loaded bean with the same type, error and exit
there is no loaded bean with the same type, this method with initialize a new bean
func (*Application) LoadBeanAndRecursion ¶
func (a *Application) LoadBeanAndRecursion(fieldType reflect.Type)
LoadBeanAndRecursion initialize a instance of a type and load it
then recursively load children of this type
func (*Application) LoadPrimeBean ¶
func (a *Application) LoadPrimeBean(fieldType reflect.Type, fieldValue reflect.Value, tag reflect.StructTag) bool
LoadPrimeBean as its name
load field in configuration and out of beanMethod in configuration
func (*Application) RecursivelyLoad ¶
func (a *Application) RecursivelyLoad(fieldType reflect.Type)
RecursivelyLoad recursively load children of a normal bean
only if there is no prime bean among the children
func (*Application) ReloadValues ¶
func (a *Application) ReloadValues()
func (*Application) Run ¶
func (a *Application) Run()
Run is the boot method of a whole Rhapsody app
Start with the Root, Get Fields of Root ¶
First, we load "PrimeBean", which mean field define in config, are basic of all bean
PrimeBean include all component Fields in config, which can defined unique name
Then, we load BeanMethodOut, which mean result of "bean method", however, what's bean method?
Bean method mean methods defined in config, return only bean(component), and all parameters can init with dependency injection returned value of Bean method is same as PrimeBean parameter value is same as normal field
And then, we load normal bean recursively
type CONF ¶
type CONF struct { }
CONF is a tag of Boot to define the path and type of config file
Usage:
type Root struct { CONF `path:"./resources/app.conf" type:"yaml"` } func main() { CreateApplication(new(Root)).Run() }
type CONNECT ¶
type CONNECT struct { }
CONNECT is a tag to mark a method with path and http CONNECT method
type Configuration ¶
type Configuration struct { }
Configuration is a tag to mark a struct as a Configuration
type DELETE ¶
type DELETE struct { }
DELETE is a tag to mark a method with path and http DELETE method
type FILE ¶
type FILE struct { }
FILE is a tag to bind a path with a file
Usage:
type UserController struct { Controller `prefix:"api/v1"` FILE `path:"static" file:"./index.html"` } type Root struct { UserController } func main() { CreateApplication(new(Root)).Run() }
type GET ¶
type GET struct { }
GET is a tag to mark a method with path and http GET method
Usage:
type UserController struct { Controller `prefix:"api/v1"` GET `path:":id" method:"GetUserInfo"` } func (u *UserController) GetUserInfo(ctx echo.Context) error { // do something } type Root struct { *UserController } func main() { CreateApplication(new(Root)).Run() }
type HandlerFunc ¶
type HandlerFunc = echo.HandlerFunc
type Logger ¶
type Logger struct {
*logging.Logger
}
Logger is a logger base on `github.com/op/go-logging`
type MdWareBean ¶
MdWareBean contains value and tag of a middleware
func NewMdWareBean ¶
NewMdWareBean is factory function of MdwareBean
type Method ¶
type Method struct { Value reflect.Value Ins []reflect.Type Name string OutValue reflect.Value InValues []reflect.Value }
Method contains value, param list and name of a 'BeanMethod'
func NewBeanMethod ¶
NewBeanMethod is factory function of Method
func (*Method) Call ¶
func (m *Method) Call(app *Application)
func (*Method) LoadIns ¶
func (m *Method) LoadIns(app *Application)
type MiddlewareFunc ¶
type MiddlewareFunc = echo.MiddlewareFunc
type OPTIONS ¶
type OPTIONS struct { }
OPTIONS is a tag to mark a method with path and http OPTIONS method
type ValueBean ¶
type ValueBean struct { Value gjson.Result ValueMap map[reflect.Type]reflect.Value MethodSet map[*Method]bool Key string Default gjson.Result }
ValueBean contains value from config file parsed by 'gjson'
ValueMap is different types the value converted to ¶
ParamSlice is the param list contain this value
func NewValueBean ¶
NewValueBean is factory function of ValueBean
func (*ValueBean) Reload ¶
func (v *ValueBean) Reload(a *Application)