Documentation ¶
Overview ¶
A simple router to help my plugin application gateway experiment
Index ¶
- func GetQueryParams(r *http.Request) map[string]interface{}
- func GetRequestBody(r *http.Request) map[string]interface{}
- func PathFromRequest(r *http.Request) []string
- func PathFromString(url string, del string) []string
- type BasicPlugin
- type STPlugin
- type ServerThing
- func (st *ServerThing) ArgsAndConfig()
- func (st *ServerThing) BuildModules() []string
- func (st *ServerThing) DeleteBuiltModules()
- func (st *ServerThing) DeleteLinkedFiles()
- func (st *ServerThing) DoPluginStuff()
- func (st *ServerThing) GetExistingModules() []string
- func (st *ServerThing) Handle(w http.ResponseWriter, r *http.Request)
- func (st *ServerThing) LoadModules(names []string)
- func (st *ServerThing) Start()
- type SubRoute
- type SubRouter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetQueryParams ¶
build args["query"] for given subroute
ex: route /cake request: /cake?flavor=chocolate args["query"] = { "flavor" : "chocolate" } request: /cake?flavor=chocolate&flavor=vanilla args["query"] = { "flavor" : ["chocolate", "vanilla"] }
func GetRequestBody ¶
build args["body"] for given subroute
ex: route /cake request: (post) /cake post body: { "flavor" : "chocolate" } args["body"] = { "flavor" : "chocolate" } + similar nesting for args["query"] based on payload, which is why both are map[string]interface
func PathFromRequest ¶
func PathFromString ¶
Types ¶
type BasicPlugin ¶ added in v0.2.0
a basic / common implementation for the interface
func (*BasicPlugin) FilePath ¶ added in v0.3.0
func (p *BasicPlugin) FilePath(url string, fileRoute string) string
func (*BasicPlugin) HandleWeb ¶ added in v0.2.0
func (p *BasicPlugin) HandleWeb(w http.ResponseWriter, r *http.Request, path []string)
func (*BasicPlugin) ReceiveInfo ¶ added in v0.2.0
func (p *BasicPlugin) ReceiveInfo(name string, fileDir string)
type STPlugin ¶
type STPlugin interface { /* void function that writes a response to the client. In most cases this can be handled by SubRouter.Handle. If your website is www.site.com, your plugin is "misc" and you register a route of "/hello", when you visit www.site.com/misc/hello your plugin "misc" will be passed a path of ["hello"]. */ HandleWeb(http.ResponseWriter, *http.Request, []string) /* void function that will receive config information from the gateway, like what name the application is being served as or what directory the files exist in. */ ReceiveInfo(name string, fileDir string) }
Interface for plugins to implement. Every plugin must export a variable that implements STPlugin. The default plugin name will be "TWTPlugin" but can be renamed with the config "plugin-variable".
type ServerThing ¶
type ServerThing struct { // handler functions from sub routed applications WebRouter map[string]func(http.ResponseWriter, *http.Request, []string) ProgArgs struct { Build bool `json:"build"` Port int `json:"port"` PluginVariable string `json:"plugin-variable"` Apps map[string]string `json:"apps"` } }
Type to receive all of the functions here
func (*ServerThing) ArgsAndConfig ¶
func (st *ServerThing) ArgsAndConfig()
build args from args & config file
func (*ServerThing) BuildModules ¶
func (st *ServerThing) BuildModules() []string
go through apps key of config and attempt to build projects into so files. current design is that a project intended for this gateway will be
/path/to/source/
src/ all golang files and packages to be built files/ files that the project may serve
func (*ServerThing) DeleteBuiltModules ¶
func (st *ServerThing) DeleteBuiltModules()
clear ./modules folder, intended to be used before building
func (*ServerThing) DeleteLinkedFiles ¶
func (st *ServerThing) DeleteLinkedFiles()
clear ./files folder
func (*ServerThing) DoPluginStuff ¶
func (st *ServerThing) DoPluginStuff()
determine whether we're loading or building modules, then do it!
func (*ServerThing) GetExistingModules ¶
func (st *ServerThing) GetExistingModules() []string
check ./modules folder for existing modules instead of building them
func (*ServerThing) Handle ¶
func (st *ServerThing) Handle(w http.ResponseWriter, r *http.Request)
Handle - main server handler
func (*ServerThing) LoadModules ¶
func (st *ServerThing) LoadModules(names []string)
load .so files in ./modules dir, optionally filtered by a config file or program arg
func (*ServerThing) Start ¶
func (st *ServerThing) Start()
type SubRoute ¶
type SubRoute struct { Path []string // ex: ["misc", "file", "thefile.png"] Method string // ex: "GET" or "POST" or "CUSTOM" or "*" Handler interface{} // handler for this route GlobIndex int // cached index of glob IsDefault bool // any router or subroute registered as * }
router routes :)
func (*SubRoute) GetRouteParams ¶
build args["route"] for given subroute.
ex: route - /cake/:flavor request: /cake/chocolate args["route"] = { "flavor": "chocolate" }