Documentation
¶
Index ¶
- Variables
- func AccessAdapter(config string) func(http.Handler) http.Handler
- func CreateUploadDir()
- func DeleteRedirectCookie(w http.ResponseWriter)
- func DeleteUserCookie(w http.ResponseWriter)
- func FileHandler() http.HandlerFunc
- func GetACL(user string, srv *Server) string
- func RedirectCookie() *securecookie.Obj
- func RedirectCookieValue(r *http.Request) string
- func SetRedirectCookie(w http.ResponseWriter, path string)
- func SetUserCookieKey(key []byte)
- func UserCookie() *securecookie.Obj
- func UserCookieValue(r *http.Request) string
- func WithUser(ctx context.Context, u *InjectedUser) context.Context
- type InjectedUser
- type Request
- type Server
- func (srv *Server) DynamicHandler(host bool) http.HandlerFunc
- func (srv *Server) DynamicHandlerFn(host bool, fs *fn.FNode) http.HandlerFunc
- func (srv *Server) InitSessions()
- func (srv *Server) LoginAdapter(host bool, userdb string) func(http.Handler) http.Handler
- func (srv *Server) Serve(secure bool, timeout int, router http.Handler, email string)
- func (srv *Server) SetMaxSessions(n int)
- func (srv *Server) Shutdown()
- func (srv *Server) StaticFileHandler(host, userspace, protect bool) http.HandlerFunc
- func (srv *Server) StaticFileHandlerFn(host bool, fs *fn.FNode) http.HandlerFunc
- func (srv *Server) WatchContext(path string)
- type SessionContext
Constants ¶
This section is empty.
Variables ¶
var TplExtensions []string = []string{".htm", ".txt", ".csv", ".json", ".g", ".ogdl", ".xml", ".xlsx", ".svg", ".ics"}
Functions ¶
func CreateUploadDir ¶
func CreateUploadDir()
func DeleteRedirectCookie ¶
func DeleteRedirectCookie(w http.ResponseWriter)
func DeleteUserCookie ¶
func DeleteUserCookie(w http.ResponseWriter)
func FileHandler ¶
func FileHandler() http.HandlerFunc
func RedirectCookie ¶
func RedirectCookie() *securecookie.Obj
RedirectCookie holds the post-login destination across the login form POST. It is a signed cookie rather than a session attribute because /login is reached anonymously, and stashing it server-side would let any unauthenticated client fill the session table.
func RedirectCookieValue ¶
func SetRedirectCookie ¶
func SetRedirectCookie(w http.ResponseWriter, path string)
func SetUserCookieKey ¶
func SetUserCookieKey(key []byte)
SetUserCookieKey sets the session cookie HMAC key. key may be any length; it is hashed to the 32 bytes securecookie requires. An empty key is ignored, leaving the default in place. Call once at startup before serving.
func UserCookie ¶
func UserCookie() *securecookie.Obj
func UserCookieValue ¶
Types ¶
type InjectedUser ¶
InjectedUser is an externally-resolved identity carried on the request context. UID maps to the "user" scalar; ACL, when non-empty, maps to the "userACL" scalar (a space-separated label set), bypassing the GetACL lookup.
type Request ¶
type Request struct {
HttpRequest *http.Request
User string
Context *ogdl.Graph
Params *ogdl.Graph
Path string
File *fn.FNode
Mime string
// Session is nil for anonymous requests: a session is only stored once a
// user authenticates.
Session *session2.Session
}
func ConvertRequest ¶
type Server ¶
type Server struct {
Host string
SecureHost string
Hosts []string
Config *ogdl.Graph
HostContexts map[string]*ogdl.Graph
Context *ogdl.Graph
Root *fn.FNode
DocRoot string
UploadDir string
DefaultUser string
UserDb *sql.DB
MaxSessions int
SessionTimeout time.Duration
Plugins []string
Login login
ContextService contextService
DomainConfig domainConfig
Templates map[string]*ogdl.Graph
Multi bool
ContextMu sync.RWMutex
// contains filtered or unexported fields
}
func New ¶
New prepares a Server{} structure initialized with configuration information and a base context that will be the initial context of each request.
func NewMulti ¶
New prepares a Server{} structure initialized with configuration information and a base context that will be the initial context of each request.
func (*Server) DynamicHandler ¶
func (srv *Server) DynamicHandler(host bool) http.HandlerFunc
DynamicHandler ...
func (*Server) DynamicHandlerFn ¶
DynamicHandlerFn ...
func (*Server) InitSessions ¶
func (srv *Server) InitSessions()
InitSessions installs the global session manager. It discards every stored session, so it must only be called at startup.
func (*Server) LoginAdapter ¶
LoginAdapter handles "Login" and "Logout"
Login: sets r.Form["user"] to the authenticated user name. Logout: removes the session Other: do nothing
func (*Server) SetMaxSessions ¶
SetMaxSessions caps the number of concurrently stored sessions. Sessions are only stored for authenticated users, so this bounds concurrent logins; past the cap the least recently used session is evicted. 0 means unlimited.
func (*Server) StaticFileHandler ¶
func (srv *Server) StaticFileHandler(host, userspace, protect bool) http.HandlerFunc
StaticFileHandler returns a handler that processes static files.
if host is true, the hostname is prepended to the path if userspace is true, the first element of a path is taken as a user
func (*Server) StaticFileHandlerFn ¶
StaticFileHandler returns a handler that processes static files.
if host is true, the hostname is prepended to the path
func (*Server) WatchContext ¶
WatchContext watches the given context.ogdl file and reloads srv.Context whenever the file is written or replaced. Intended to be run as a goroutine.
type SessionContext ¶
type SessionContext struct {
Parent *ogdl.Graph // points to srv.Context or a host context; never written
// contains filtered or unexported fields
}
SessionContext is a lightweight per-request overlay over the server's read-only context. Only session-specific values (user, userACL, R.*) are stored locally; everything else resolves from Parent without copying.
func (*SessionContext) Graph ¶
func (sc *SessionContext) Graph() *ogdl.Graph
Graph builds a merged *ogdl.Graph for the template engine. Local nodes come first so they shadow parent entries of the same name. Parent entries are wrapped in shell nodes so writes during template processing cannot reach the shared srv.Context.
func (*SessionContext) Set ¶
func (sc *SessionContext) Set(key string, val interface{})
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
ctxreg
Package ctxreg is a dependency-free registry for template-context objects.
|
Package ctxreg is a dependency-free registry for template-context objects. |
|
plugins/etoolsctx
Package etoolsctx registers electronics/etools under the "etools" context name.
|
Package etoolsctx registers electronics/etools under the "etools" context name. |
|
plugins/filesctx
Package filesctx registers golib/files under the "files" context name.
|
Package filesctx registers golib/files under the "files" context name. |
|
plugins/gosqlctx
Package gosqlctx registers golib/gosql under the "sql" context name.
|
Package gosqlctx registers golib/gosql under the "sql" context name. |
|
plugins/htmlctx
Package htmlctx registers golib/html under the "html" context name.
|
Package htmlctx registers golib/html under the "html" context name. |
|
plugins/isolationctx
Package isolationctx registers electronics/isolation under the "isolation" context name.
|
Package isolationctx registers electronics/isolation under the "isolation" context name. |
|
plugins/stringsctx
Package stringsctx registers golib/strings under the "strings" context name.
|
Package stringsctx registers golib/strings under the "strings" context name. |
|
Gserver is a web server.
|
Gserver is a web server. |