Documentation
¶
Overview ¶
*
- newt.go an implementation of the Newt URL router. *
- @author R. S. Doiel
Index ¶
- Constants
- Variables
- func FmtHelp(src string, appName string, version string, releaseDate string, ...) string
- func JSONSrcToFrontMatter(src []byte) (string, error)
- func Run(in io.Reader, out io.Writer, eout io.Writer, args []string, dryRun bool) int
- type Config
- type EvalType
- type RdslBasename
- type RdslDOI
- type RdslDay
- type RdslExtname
- type RdslIsbn
- type RdslIsbn10
- type RdslIsbn13
- type RdslIsni
- type RdslIssn
- type RdslMonth
- type RdslORCID
- type RdslString
- type RdslYear
- type Route
- type RouteDSL
- type RouteDSLType
- type Router
- func (router *Router) Getenv(key string) string
- func (router *Router) Newt(next http.Handler) http.Handler
- func (router *Router) OverlayEnv(m map[string]string) map[string]string
- func (router *Router) ReadCSV(fName string) error
- func (router *Router) RequestDataAPI(rNo int, apiURL string, body []byte) ([]byte, string, int)
- func (router *Router) RequestPandoc(rNo int, src []byte) ([]byte, string, int)
- func (router *Router) ResolveApiURL(no int, m map[string]string) (string, bool)
- func (router *Router) ResolveRoute(u string, method string) (int, map[string]string, bool)
- func (router *Router) Setenv(key string, val string)
- func (router *Router) WriteResponse(w http.ResponseWriter, rNo int, src []byte)
Constants ¶
const ( StartVar = "${" EndVar = "}" )
const ( // Version number of release Version = "0.0.1" // ReleaseDate, the date version.go was generated ReleaseDate = "2023-06-05" // ReleaseHash, the Git hash when version.go was generated ReleaseHash = "c5f3051" LicenseText = `` /* 1430-byte string literal not displayed */ )
Variables ¶
var ( // RdslTypes is a map to the types defined in route_dsl_types.go RouteTypes = map[string]EvalType{ "String": new(RdslString).EvalType, "Year": new(RdslYear).EvalType, "Month": new(RdslMonth).EvalType, "Day": new(RdslDay).EvalType, "Basename": new(RdslBasename).EvalType, "Extname": new(RdslExtname).EvalType, "Isbn10": new(RdslIsbn10).EvalType, "Isbn13": new(RdslIsbn13).EvalType, "Isbn": new(RdslIsbn).EvalType, "Issn": new(RdslIssn).EvalType, "DOI": new(RdslDOI).EvalType, "Isni": new(RdslIsni).EvalType, "ORCID": new(RdslORCID).EvalType, } )
Functions ¶
func FmtHelp ¶
func FmtHelp(src string, appName string, version string, releaseDate string, releaseHash string) string
FmtHelp lets you process a text block with simple curly brace markup.
func JSONSrcToFrontMatter ¶
toFrontMatter converts JSON source to front matter for a Pandoc Markdown document.
Types ¶
type Config ¶
type Config struct { // Port is the name of the localhost port Newt will listen on. Port string `json:"newt_port,omitempty" yaml:"newt_port,omitempty"` // Routes is the CSV filename that data API routes are read from Routes string `json:"newt_routes,omitempty" yaml:"newt_routes,omitempty"` // Env is a list of environment variables that can be passed // through to the RouteDSL when rendering JSON data API calls or // calls to Pandoc server. Env []string `json:"newt_env,omitempty" yaml:"newt_env,omitempty"` // Htdocs holds any static files you want to make available through // Newt router. Htdocs string `json:"newt_htdocs,omitempty" yaml:"newt_htdocs,omitempty"` }
func LoadConfig ¶
LoadConfig loads a configuration return a Config object and error value.
type RdslBasename ¶
type RdslBasename struct { }
type RdslExtname ¶
type RdslExtname struct { }
type RdslIsbn10 ¶
type RdslIsbn10 struct { }
type RdslIsbn13 ¶
type RdslIsbn13 struct { }
type Route ¶
type Route struct { // ReqPath, a path described by RouteDSL from a browser or front end web server ReqPath *RouteDSL // ReqMethod, the request HTTP method (e.g. GET, POST, PUT, DELETE, PATCH, HEAD) ReqMethod string // ApiURL is the URL used to contact the data source (e.g. PostgREST, Solr, Elasticsearch) ApiURL string // ApiMethod indicates the HTTP method to be used to contact the data source api ApiMethod string // ApiContentType is the content type to be used to contact the data source api ApiContentType string // PandocTemplate holds the source to a Pandoc template PandocTemplate string // ResHeaders holds any additional response headers to send back to the // browser or front end web server ResHeaders map[string]string }
Route describes an individual route, maps to the columns of a route CSV file.
func (*Route) HasReqMethod ¶
type RouteDSL ¶
type RouteDSL struct { Src string `json:"src"` Dirs []string `json:"dirs,omitempty"` Base string `json:"base,omitempty"` Ext string `json:"ext,omitempty"` // VarToType maps the variable name to a var defn VarToType map[string]string `json:"var_to_types,omitempty"` // Types maps type implementation description Types map[string]string `json:"-"` // Type name to function to Eval function (validates a variable's // value and extracts a value) TypeFn map[string]EvalType `json:"-"` }
RouteDSL holds the attributes need to decode a RouteDSL expression, match and decode against path values.
func NewRouteDSL ¶
NewRouteDSL takes a RouteDSL expression and returns a RouteDSLExpresion structure and error value.
func (*RouteDSL) Eval ¶
Eval takes a path value and compares it with a Path expression. It returns a status boolean, map of variable names to values.
func (*RouteDSL) RegisterType ¶
func (rdsl *RouteDSL) RegisterType(tName string, t RouteDSLType) error
RegisterType maps a type name to a a RouteDSLType interface. RouteDSLType interface must defined EvalType.
type RouteDSLType ¶
type RouteDSLType interface { // EvalType takes an variable type expression like EvalType(string, string) (string, bool) }
RouteDSLType
type Router ¶
func (*Router) Newt ¶
Newt implements the router as an http middleware. This allows our router to be used more generally and gives us options like having the Newt application be both a data router and static file server.
func (*Router) OverlayEnv ¶
OverlayEnv merges the env with m (a map[string]string). For keys in common the value in env replaces that in m.
func (*Router) RequestDataAPI ¶
RequestDataAPI
func (*Router) RequestPandoc ¶
RequestPandoc
func (*Router) ResolveApiURL ¶
ResolveApiURL takes an in bound Request URL, matches it to a route and returns a resolved JSON data API URL based the related api_url. It included an error if something went wrong.
func (*Router) ResolveRoute ¶
func (*Router) WriteResponse ¶
func (router *Router) WriteResponse(w http.ResponseWriter, rNo int, src []byte)
WriteResponse