Version: v0.7.4 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2021 License: MIT Imports: 38 Imported by: 0



Provides all of the functionality to create and deploy web applications with the Dashborg framework.



View Source
const (
	TlsKeyFileName         = "dashborg-client.key"
	TlsCertFileName        = "dashborg-client.crt"
	DefaultProcName        = "default"
	DefaultZoneName        = "default"
	DefaultPanelName       = "default"
	DefaultLocalServerAddr = "localhost:8082"
	DefaultConsoleHost     = "console.dashborg.net"
	DefaultJWTValidFor     = 24 * time.Hour
	DefaultJWTUserId       = "jwt-user"
	DefaultJWTRole         = RoleUser
View Source
const (
	RoleSuper  = "*"
	RolePublic = "public"
	RoleUser   = "user"
View Source
const (
	AccTypeAnon       = "anon"
	AccTypeFree       = "free"
	AccTypePro        = "pro"
	AccTypeEnterprise = "enterprise"
View Source
const (
	RequestMethodGet  = "GET"
	RequestMethodPost = "POST"
View Source
const (
	VisTypeHidden        = "hidden"  // always hide
	VisTypeDefault       = "default" // shown if user has permission
	VisTypeAlwaysVisible = "visible" // always show
View Source
const (
	AppRuntimeSubPath = "/_/runtime"
	AppHtmlSubPath    = "/_/html"
View Source
const (
	MimeTypeDashborgHtml = "text/x-dashborg-html"
	MimeTypeHtml         = "text/html"
	MimeTypeJson         = "application/json"
	MimeTypeDashborgApp  = "application/x-dashborg+json"
View Source
const (
	FileTypeStatic         = "static"
	FileTypeRuntimeLink    = "rt-link"
	FileTypeAppRuntimeLink = "rt-app-link"
	FileTypeDir            = "dir"
	FileTypeApp            = "app"
View Source
const AuthScopeZone = "zone"
View Source
const ClientVersion = "go-0.7.4"
View Source
const MaxAppConfigSize = 10000
View Source
const MaxAuthExp = 24 * time.Hour
View Source
const RootAppPath = "/_/apps"
View Source
const RootProcPath = "/_/procs"
View Source
const RtnSetDataPath = "@rtn"


View Source
var DefaultJWTOpts = &JWTOpts{
	ValidFor: DefaultJWTValidFor,
	Role:     DefaultJWTRole,
	UserId:   DefaultJWTUserId,
View Source
var NotConnectedErr = dasherr.ErrWithCodeStr(dasherr.ErrCodeNotConnected, "DashborgCloudClient is not Connected")


func AppPathFromName added in v0.7.0

func AppPathFromName(appName string) string

Given an app name, returns the canonical path (e.g. /_/apps/[appName])

func UpdateFileOptsFromReadSeeker added in v0.7.0

func UpdateFileOptsFromReadSeeker(r io.ReadSeeker, fileOpts *FileOpts) error

Will call Seek(0, 0) on the reader twice, once at the beginning and once at the end. If an error is returned, the seek position is not specified. If no error is returned the reader will be reset to the beginning. A []byte can be wrapped in a bytes.Buffer to use this function (error will always be nil)


type App added in v0.6.0

type App struct {
	// contains filtered or unexported fields

func (*App) AppConfig added in v0.6.0

func (app *App) AppConfig() (AppConfig, error)

Returns the App's AppConfig struct suitable for marshaling into JSON. Used internally to send the app definition to the Dashborg service. Not normally called by user facing code.

func (*App) AppFSClient added in v0.7.0

func (app *App) AppFSClient() *DashFSClient

Returns a FSClient that is rooted at AppPath() (/_/apps/[app-name]). Allows you to write data/files that are local to the app. Can be accessed in the UI using /@app/[relative-path].

func (*App) AppName added in v0.6.0

func (app *App) AppName() string

Returns the app's name.

func (*App) AppPath added in v0.7.0

func (app *App) AppPath() string

Returns the canonical app path - /_/apps/[app-name]

func (*App) ClearHtml added in v0.7.0

func (app *App) ClearHtml()

Clear all of an app's HTML settings (static, dynamic, watches, etc.)

func (*App) Err added in v0.7.0

func (app *App) Err() error

Returns any error during the setup phase of an app. Errors can be checked manually after functions like Runtime().Handler(), but will also be returned when the app is written or connected to the Dashborg service.

func (*App) HasExternalRuntime added in v0.7.0

func (app *App) HasExternalRuntime() bool

Returns true if the app has an external runtime

func (*App) Runtime added in v0.6.0

func (app *App) Runtime() *AppRuntimeImpl

Returns the app's internal runtime. Used to set handler functions. Errors that happen while setting Handlers will be available in app.Err().

func (*App) SetAllowedRoles added in v0.6.0

func (app *App) SetAllowedRoles(roles ...string)

Set the roles that are allowed to access this app. By default the allowed roles are set to ["user"].

func (*App) SetAppTitle added in v0.6.0

func (app *App) SetAppTitle(title string)

Sets an title for this app (that shows up in the App Switcher and in the navigation bar). If not given, the app's title will be set to the app's name. This is a static value (cannot be changed at runtime) and must be set before WriteApp is called. To change the title at runtime, use the client path $state.dashborg.apptitle.

func (*App) SetAppVisibility added in v0.6.0

func (app *App) SetAppVisibility(visType string, visOrder float64)

SetAppVisibility controls whether the app shows in the UI's app-switcher (see VisType constants) Apps will be sorted by displayOrder (and then AppTitle). displayOrder of 0 (the default) will sort to the end of the list, not the beginning visType is either VisTypeHidden, VisTypeDefault, or VisTypeAlwaysVisible

func (*App) SetExternalAppRuntimePath added in v0.7.0

func (app *App) SetExternalAppRuntimePath(runtimePath string)

Sets an external runtime path. If this is set, the app's own Runtime() will not be used. Should call WriteApp, not WriteAndConnectApp if an external runtime is specified.

func (*App) SetHtml added in v0.6.0

func (app *App) SetHtml(htmlStr string)

Set a static HTML string as the app's HTML. Will be written to /@app/_/html

func (*App) SetHtmlFromFile added in v0.6.0

func (app *App) SetHtmlFromFile(fileName string)

Set an app's HTML from the given fileName. Will be written to /@app/_/html

func (*App) SetHtmlFromRuntime added in v0.7.0

func (app *App) SetHtmlFromRuntime()

For dynamic HTML. To get app's HTML, Dashborg will call the app runtime's HTML handler (see App.Runtime().SetHtmlHandler).

func (*App) SetInitRequired added in v0.7.0

func (app *App) SetInitRequired(initRequired bool)

If set to true, Dashborg will call the runtime's init method (see App.Runtime().SetInitHandler) before loading the app. If InitRequired is set, app cannot be viewed offline (App.SetOfflineAccess should be false). Any error returned in the init function will cause the app not to load.

func (*App) SetOfflineAccess added in v0.7.0

func (app *App) SetOfflineAccess(offlineAccess bool)

offline mode type is either OfflineModeEnable or OfflineModeDisable

func (*App) SetPagesEnabled added in v0.7.3

func (app *App) SetPagesEnabled(pagesEnabled bool)

Set PagesEnabled to true to allow your app to serve different frontend/UI pages. When PagesEnabled is false, the app will only have one logical page (single page app).

func (*App) SetRuntime added in v0.7.0

func (app *App) SetRuntime(apprt *AppRuntimeImpl)

Set a different AppRuntimeImpl as this app's runtime. Not normally used except in special cases. Should not set the runtime after the app is already connected to the Dashborg service.

func (*App) WatchHtmlFile added in v0.7.0

func (app *App) WatchHtmlFile(fileName string, watchOpts *WatchOpts)

Set an app's HTML from the given fileName. *After* the app is connected or written to the Dashborg service, the function will set up an fsnotify watcher on the given file. If the file is changed, it will re-upload the file to the Dashborg service. Content will be written to /@app/_/html

type AppConfig added in v0.6.0

type AppConfig struct {
	AppName         string   `json:"appname"`
	ClientVersion   string   `json:"clientversion"`
	AppTitle        string   `json:"apptitle,omitempty"`
	AppVisType      string   `json:"appvistype,omitempty"`
	AppVisOrder     float64  `json:"appvisorder,omitempty"`
	AllowedRoles    []string `json:"allowedroles"`
	InitRequired    bool     `json:"initrequired"`
	OfflineAccess   bool     `json:"offlineaccess"`
	HtmlPath        string   `json:"htmlpath"`
	InitialHtmlPage string   `json:"initialhtmlpage"`
	RuntimePath     string   `json:"runtimepath,omitempty"` // empty for ./runtime
	PagesEnabled    bool     `json:"pagesenabled,omitempty"`

AppConfig is passed as JSON to the container. this struct helps with marshaling/unmarshaling the structure. The AppConfig struct is generated by the App class. Normally end-users do not have to deal with this struct directly.

func (*AppConfig) Validate added in v0.7.0

func (config *AppConfig) Validate() error

Validates the AppConfig. Returns an error if the config is not valid.

type AppRequest added in v0.7.0

type AppRequest struct {
	// contains filtered or unexported fields

The full app request object. All of the information about the request is encapsulated in this struct. Note that "pure" requests and link runtime requests cannot access all of the functionality of the AppRequest (sepecifically the parts that cause side effects in the UI). The limited API for those requests is encapsulated in the Request interface.

func (*AppRequest) AddDataOp added in v0.7.0

func (req *AppRequest) AddDataOp(op string, path string, data interface{}) error

AddDataOp is a more generic form of SetData. It allows for more advanced setting of data in the frontend data model -- like "append" or "setunless".

func (*AppRequest) AuthData added in v0.7.0

func (req *AppRequest) AuthData() *AuthAtom

Returns the authentication (AuthAtom) attached to this request.

func (*AppRequest) BindAppState added in v0.7.0

func (req *AppRequest) BindAppState(obj interface{}) error

Binds a Go struct to the application state passed in this request. Used for special cases when the Runtime's AppState is not sufficient.

func (*AppRequest) BindData added in v0.7.0

func (req *AppRequest) BindData(obj interface{}) error

Binds a Go struct to the data passed in this request. Used for special cases or when the func reflection binding is not sufficient. Used just like json.Unmarshal().

func (*AppRequest) Context added in v0.7.0

func (req *AppRequest) Context() context.Context

Returns a context that controls this request. This context comes from the initiating gRPC request. When the gRPC request times out, this context will expire.

func (*AppRequest) GetError added in v0.7.0

func (req *AppRequest) GetError() error

Returns the error (if any) that has been set on this request.

func (*AppRequest) GetPageName added in v0.7.3

func (req *AppRequest) GetPageName() string

Returns the current frontend page name that generated this request.

func (*AppRequest) InvalidateData added in v0.7.0

func (req *AppRequest) InvalidateData(pathRegexp string) error

Call from a handler to force the client to invalidate and re-pull data that matches path. Path is a regular expression. If pathRegexp is set to empty string, it will invalidate all frontend data (equivalent to ".*").

func (*AppRequest) IsDone added in v0.7.0

func (req *AppRequest) IsDone() bool

Returns true once the response has already been sent back to the Dashborg service. Most methods will return errors (or have no effect) once the request is done.

func (*AppRequest) NavToPage added in v0.7.3

func (req *AppRequest) NavToPage(pageName string, params interface{}) error

Navigates the application to the given pageName with the given parameters. Should only be called for apps that have PagesEnabled.

func (*AppRequest) RawData added in v0.7.0

func (req *AppRequest) RawData() RawRequestData

Returns the raw JSON request data (auth, app state, and parameter data). Used when you require special/custom JSON handling that the other API functions cannot handle.

func (*AppRequest) RequestInfo added in v0.7.0

func (req *AppRequest) RequestInfo() RequestInfo

Returns RequestInfo which contains basic information about this request (StartTime, Path, AppName, FeClientId, etc.)

func (*AppRequest) SetBlob added in v0.7.0

func (req *AppRequest) SetBlob(path string, mimeType string, reader io.Reader) error

SetBlobData sets blob data at a particular FE path. Often calling SetBlob can be easier than creating a separate handler that returns BlobData -- e.g. getting a data-table and a graph image.

func (*AppRequest) SetBlobFromFile added in v0.7.0

func (req *AppRequest) SetBlobFromFile(path string, mimeType string, fileName string) error

Calls SetBlobData with the the contents of fileName. Do not confuse path with fileName. path is the location in the FE data model to set the data. fileName is the local fileName to read blob data from.

func (*AppRequest) SetData added in v0.7.0

func (req *AppRequest) SetData(path string, data interface{}) error

SetData is used to return data to the client. Will replace the contents of path with data. Calls AddDataOp with the op "set".

func (*AppRequest) SetError added in v0.7.0

func (req *AppRequest) SetError(err error)

Sets an error to be returned from this request. Normally you can just return the error from your top-level handler function. This method is for special cases where that's not possible.

func (*AppRequest) SetHtmlPage added in v0.7.2

func (req *AppRequest) SetHtmlPage(htmlPage string) error

Should normally call NavToPage (if PagesEnabled). This call is a low-level call that swaps out the HTML view on the frontend. It does not update the URL.

type AppRuntimeImpl added in v0.6.0

type AppRuntimeImpl struct {
	// contains filtered or unexported fields

func MakeAppRuntime added in v0.6.0

func MakeAppRuntime() *AppRuntimeImpl

Creates an app runtime. Normally you should use the App class to manage applications which creates an AppRuntime automatically. This is for special low-level use cases.

func (*AppRuntimeImpl) AddRawMiddleware added in v0.6.0

func (apprt *AppRuntimeImpl) AddRawMiddleware(name string, mwFunc MiddlewareFuncType, priority float64)

Adds a middleware function to this runtime.

func (*AppRuntimeImpl) Err added in v0.7.0

func (apprt *AppRuntimeImpl) Err() error

Returns any setup errors that the runtime encountered.

func (*AppRuntimeImpl) Handler added in v0.6.0

func (apprt *AppRuntimeImpl) Handler(name string, handlerFn interface{}, opts ...*HandlerOpts)

Handler registers a handler using reflection. Return value must be return void, interface{}, error, or (interface{}, error). First optional argument to the function is a *dash.AppRequest. Second optional argument is the AppStateType (if one has been set in the app runtime). The rest of the arguments are mapped to the request Data as an array. If request Data is longer, the arguments are ignored. If request Data is shorter, the missing arguments are set to their zero value. If request Data is not an array, it will be converted to a single element array, if request Data is null it will be converted to a zero-element array. The handler will throw an error if the Data or AppState values cannot be converted to their respective go types (using json.Unmarshal).

func (*AppRuntimeImpl) PureHandler added in v0.7.0

func (apprt *AppRuntimeImpl) PureHandler(name string, handlerFn interface{}, opts ...*HandlerOpts)

func (*AppRuntimeImpl) RemoveMiddleware added in v0.6.0

func (apprt *AppRuntimeImpl) RemoveMiddleware(name string)

Removes a middleware function from this runtime

func (*AppRuntimeImpl) RunHandler added in v0.6.0

func (apprt *AppRuntimeImpl) RunHandler(req *AppRequest) (interface{}, error)

Runs an application handler given an AppRequest. This method is not normally used by end users, it is used by the Dashborg runtime to dispatch requests to this runtime.

func (*AppRuntimeImpl) SetAppStateType added in v0.6.0

func (apprt *AppRuntimeImpl) SetAppStateType(appStateType reflect.Type)

Sets the type to unmarshal the application state into. Must be set before the app is connected to the Dashborg service.

func (*AppRuntimeImpl) SetHtmlHandler added in v0.7.0

func (apprt *AppRuntimeImpl) SetHtmlHandler(handlerFn interface{}, opts ...*HandlerOpts)

Set the application's dynamic HTML handler. Only used if app SetHtmlFromRuntime() has been called. Should return a BlobReturn struct with mime type of text/html.

func (*AppRuntimeImpl) SetInitHandler added in v0.6.0

func (apprt *AppRuntimeImpl) SetInitHandler(handlerFn interface{}, opts ...*HandlerOpts)

Set the init handler. Only called if InitRequired is set to true in the application. Init handlers run before the application loads, and can set up the internal application state or perform validation. If an error is returned the app will not load. The init handler is often used to validate url parameters and convert them to application state.

func (*AppRuntimeImpl) SetPageHandler added in v0.7.3

func (apprt *AppRuntimeImpl) SetPageHandler(pageName string, handlerFn interface{})

Set the init function for an application page. Only used when the app has PagesEnabled.

func (*AppRuntimeImpl) SetRawHandler added in v0.6.0

func (apprt *AppRuntimeImpl) SetRawHandler(handlerName string, handlerFn func(req *AppRequest) (interface{}, error), opts *HandlerOpts) error

Sets a raw handler. Normal code should use Handler() or PureHandler() which internally calls this method.

type AuthAtom added in v0.6.0

type AuthAtom struct {
	Type     string                 `json:"type"` // auth type (password, noauth, dashborg, deauth, or user-defined)
	Ts       int64                  `json:"ts"`   // expiration Ts (ms) of this auth atom
	RoleList []string               `json:"role"`
	Id       string                 `json:"id,omitempty"`
	Data     map[string]interface{} `json:"data,omitempty"`

func (*AuthAtom) GetRoleList added in v0.7.0

func (aa *AuthAtom) GetRoleList() []string

func (*AuthAtom) HasRole added in v0.7.0

func (aa *AuthAtom) HasRole(role string) bool

Returns AuthAtom role. If AuthAtom is nil, returns "public"

func (*AuthAtom) IsSuper added in v0.7.0

func (aa *AuthAtom) IsSuper() bool

type BlobReturn added in v0.7.0

type BlobReturn struct {
	Reader   io.Reader
	MimeType string

Special return value from handler functions to return BLOB data.

type Config

type Config struct {
	// DASHBORG_ACCID, set to force an AccountId (must match certificate).  If not set, AccountId is set from certificate file.
	// If AccId is given and AutoKeygen is true, and key/cert files are not found, Dashborg will create a new self-signed
	//     keypair using the AccId given.
	// If AccId is given, and the certificate does not match, this will cause a panic.
	AccId string

	// Set to true for unregistered/unclaimed accounts.  New accounts will only be created if this flag is set.
	AnonAcc bool

	// DASHBORG_ZONE defaults to "default"
	ZoneName string

	// Process Name Attributes.  Only ProcName is required
	ProcName string            // DASHBORG_PROCNAME (set from executable filename if not set)
	ProcIKey string            // DASHBORG_PROCIKEY (optional, user-specified key to identify procs in a cluster)
	ProcTags map[string]string // optional, user-specified key/values to identify this proc

	KeyFileName  string // DASHBORG_KEYFILE private key file (defaults to dashborg-client.key)
	CertFileName string // DASHBORG_CERTFILE certificate file, CN must be set to your Dashborg Account Id.  (defaults to dashborg-client.crt)

	// Create a self-signed key/cert if they do not exist.
	// If AccId is set, will create a key with that AccId, if AccId is not set, it will create a new random AccId.
	AutoKeygen bool

	// DASHBORG_VERBOSE, set to true for extra debugging information
	Verbose bool

	// close this channel to force a shutdown of the Dashborg Cloud Client
	ShutdownCh chan struct{}

	// These are for internal testing, should not normally be set by clients.
	Env         string // DASHBORG_ENV
	GrpcHost    string // DASHBORG_GRPCHOST
	GrpcPort    int    // DASHBORG_GRPCPORT
	ConsoleHost string // DASHBORG_CONSOLEHOST

	// Used to override the JWT keys (valid time, userid, and role) that are printed to the log when
	// apps are connected to the Dashborg service.
	// To suppress writing JWT keys to the log, set NoJWT in this structure.
	// If left as nil, DefaultJWTOpts will be used.
	JWTOpts *JWTOpts

	Logger *log.Logger // use to override the SDK's logger object
	// contains filtered or unexported fields

func (*Config) GetJWTOpts added in v0.7.0

func (c *Config) GetJWTOpts() *JWTOpts

Returns the config's JWTOpts structure. Does not return nil. If config's JWTOpts is nil, will return DefaultJWTOpts

func (*Config) MakeAccountJWT added in v0.5.2

func (c *Config) MakeAccountJWT(jwtOpts *JWTOpts) (string, error)

Creates a JWT token from the public/private keypair. The jwtOpts parameter, if not nil, will override the config's JWTOpts field.

func (*Config) MustMakeAccountJWT added in v0.5.2

func (c *Config) MustMakeAccountJWT(jwtOpts *JWTOpts) string

Calls MakeAccountJWT, and panics on error.

type DashAppClient added in v0.7.0

type DashAppClient struct {
	// contains filtered or unexported fields

func (*DashAppClient) ConnectAppRuntime added in v0.7.0

func (dac *DashAppClient) ConnectAppRuntime(app *App) error

Connects the app's runtime without modifying any settings (does not write the app config to the Dashborg service). Note that a different WriteApp or WriteAndConenctApp must have already created the app.

func (*DashAppClient) LoadApp added in v0.7.0

func (dac *DashAppClient) LoadApp(appName string, createIfNotFound bool) (*App, error)

Tries to load an app from the Dashborg service with the given name. If no existing app is found then if createIfNotFound is false will return nil, nil. If createIfNotFound is true, will return NewApp(appName).

func (*DashAppClient) MakeAppUrl added in v0.7.0

func (dac *DashAppClient) MakeAppUrl(appNameOrPath string, jwtOpts *JWTOpts) (string, error)

Creates a URL to link to an app given its name. Optional jwtOpts to override the config's default jwt options.

func (*DashAppClient) NewApp added in v0.7.0

func (dac *DashAppClient) NewApp(appName string) *App

Create a new app with the given name. The app is just created client side, it is not written to the server. Invalid names will be reported in App.Err()

func (*DashAppClient) NewAppFromConfig added in v0.7.0

func (dac *DashAppClient) NewAppFromConfig(cfg AppConfig) (*App, error)

Create a new app from the passed in AppConfig. Config must be valid and complete. Normal end users should use LoadApp(), not this function.

func (*DashAppClient) RemoveApp added in v0.7.0

func (dac *DashAppClient) RemoveApp(appName string) error

Removes the app and any static data/runtimes/files under the canonical app root. So any file that was created using the AppFSClient() will also be removed. Any connected runtimes will also be disconnected.

func (*DashAppClient) WriteAndConnectApp added in v0.7.0

func (dac *DashAppClient) WriteAndConnectApp(app *App) error

Writes the app to the Dashborg service and connects the app's runtime to receive requests. If an app uses an external runtime, you should call WriteApp(), not WriteAndConnectApp().

func (*DashAppClient) WriteApp added in v0.7.0

func (dac *DashAppClient) WriteApp(app *App) error

Writes the app to the Dashborg service. Note that the app runtime will *not* be connected. This is used to create or update an app's settings, offline apps, or apps with external runtimes.

type DashCloudClient added in v0.7.0

type DashCloudClient struct {
	Lock      *sync.Mutex
	StartTime time.Time
	ProcRunId string
	Config    *Config
	Conn      *grpc.ClientConn
	DBService dashproto.DashborgServiceClient
	ConnId    *atomic.Value
	LinkRtMap map[string]LinkRuntime
	DoneCh    chan bool
	PermErr   bool
	ExitErr   error
	AccInfo   accInfoType

func ConnectClient added in v0.7.0

func ConnectClient(config *Config) (*DashCloudClient, error)

func (*DashCloudClient) AppClient added in v0.7.0

func (pc *DashCloudClient) AppClient() *DashAppClient

func (*DashCloudClient) FSClientAtRoot added in v0.7.0

func (pc *DashCloudClient) FSClientAtRoot(rootPath string) (*DashFSClient, error)

func (*DashCloudClient) GetExitError added in v0.7.0

func (pc *DashCloudClient) GetExitError() error

Returns nil if client is still running. Returns error (reason for shutdown) if client has stopped.

func (*DashCloudClient) GlobalFSClient added in v0.7.0

func (pc *DashCloudClient) GlobalFSClient() *DashFSClient

func (*DashCloudClient) IsConnected added in v0.7.0

func (pc *DashCloudClient) IsConnected() bool

func (*DashCloudClient) UploadFile added in v0.7.1

func (pc *DashCloudClient) UploadFile(ctx context.Context, r io.Reader, accId string, uploadId string, uploadKey string) error

func (*DashCloudClient) WaitForShutdown added in v0.7.0

func (pc *DashCloudClient) WaitForShutdown() error

returns the reason for shutdown (GetExitError())

type DashFSClient added in v0.7.0

type DashFSClient struct {
	// contains filtered or unexported fields

func (*DashFSClient) ConnectLinkRuntime added in v0.7.1

func (fs *DashFSClient) ConnectLinkRuntime(path string, runtime LinkRuntime) error

Connects a link runtime *without* creating or updating its FileInfo. Note the difference between this function and LinkRuntime(). LinkRuntime() takes FileOpts and will create/update the path.

func (*DashFSClient) DirInfo added in v0.7.0

func (fs *DashFSClient) DirInfo(path string, dirOpts *DirOpts) ([]*FileInfo, error)

Gets the directory info assocaited with path. dirOpts may be nil (in which case defaults are used). If the directory does not exist, []*FileInfo will have length of 0, and error will be nil.

func (*DashFSClient) FileInfo added in v0.7.0

func (fs *DashFSClient) FileInfo(path string) (*FileInfo, error)

Gets the FileInfo associated with path. If the file is not found, will return nil, nil.

func (*DashFSClient) LinkAppRuntime added in v0.7.0

func (fs *DashFSClient) LinkAppRuntime(path string, apprt LinkRuntime, fileOpts *FileOpts) error

Connects an AppRuntime to the given path. Normally this function is not called directly. When an app is connected to the Dashborg backend, its runtime is also linked.

func (*DashFSClient) LinkRuntime added in v0.7.0

func (fs *DashFSClient) LinkRuntime(path string, rt LinkRuntime, fileOpts *FileOpts) error

Connects a LinkRuntime to the given path.

func (*DashFSClient) MakePathUrl added in v0.7.0

func (fs *DashFSClient) MakePathUrl(path string, jwtOpts *JWTOpts) (string, error)

Creates a /@fs/ URL link to the given path. If jwtOpts are specified, it will override the defaults in the config.

func (*DashFSClient) MustMakePathUrl added in v0.7.1

func (fs *DashFSClient) MustMakePathUrl(path string, jwtOpts *JWTOpts) string

Calls MakePathUrl, panics on error.

func (*DashFSClient) RemovePath added in v0.7.0

func (fs *DashFSClient) RemovePath(path string) error

Removes (deletes) the specified path from Dashborg FS.

func (*DashFSClient) SetJsonPath added in v0.7.0

func (fs *DashFSClient) SetJsonPath(path string, data interface{}, fileOpts *FileOpts) error

Sets static JSON data to the given path. FileOpts is optional (type will be set to "static", and mimeType to "application/json").

func (*DashFSClient) SetPathFromFile added in v0.7.0

func (fs *DashFSClient) SetPathFromFile(path string, fileName string, fileOpts *FileOpts) error

Sets the data from the given fileName as static data to the given Dashborg FS path. fileOpts is required, and must specify at least a mimeType for the file contents.

func (*DashFSClient) SetRawPath added in v0.7.0

func (fs *DashFSClient) SetRawPath(path string, r io.Reader, fileOpts *FileOpts, runtime LinkRuntime) error

Low-level function to set a Dashborg FS path. Not normally called by end users. This function is called by SetJsonPath, LinkRuntime, LinkAppRuntime, SetPathFromFile, SetStaticPath, and WatchFile.

func (*DashFSClient) SetStaticPath added in v0.7.0

func (fs *DashFSClient) SetStaticPath(path string, r io.ReadSeeker, fileOpts *FileOpts) error

Sets static data to the given Dashborg FS path, with data from an io.ReadSeeker. Will always seek to the beginning of the stream (to compute the SHA-256 and size using UpdateFileOptsFromReadSeeker).

func (*DashFSClient) WatchFile added in v0.7.0

func (fs *DashFSClient) WatchFile(path string, fileName string, fileOpts *FileOpts, watchOpts *WatchOpts) error

First calls SetPathFromFile. If that that fails, an error is returned and the file will *not* be watched (watching only starts if this function returns nil). The given file will be watched using fsnotify. Every time fsnotify detects a file modification, the file will be be re-uploaded using SetPathFromFile. watchOpts may be nil, which will use default settings (Throttle time of 1 second, no shutdown channel). This is function is recommended for use in development environments.

type DirOpts added in v0.7.0

type DirOpts struct {
	RoleList   []string `json:"rolelist"`
	ShowHidden bool     `json:"showhidden"`
	Recursive  bool     `json:"recursive"`

Options to pass to DashFSClient.DirInfo()

type FileInfo added in v0.7.0

type FileInfo struct {
	ParentDir     string   `json:"parentdir"`
	FileName      string   `json:"filename"`
	Path          string   `json:"path"`
	Size          int64    `json:"size"`
	CreatedTs     int64    `json:"createdts"`
	UpdatedTs     int64    `json:"updatedts"`
	Sha256        string   `json:"sha256"`
	FileType      string   `json:"filetype"`
	MimeType      string   `json:"mimetype"`
	AllowedRoles  []string `json:"allowedroles"`
	EditRoles     []string `json:"editroles"`
	Display       string   `json:"display,omitempty"`
	MetadataJson  string   `json:'metadata,omitempty"` // json-string
	Description   string   `json:"description,omitempty"`
	Hidden        bool     `json:"hidden,omitempty"`
	Removed       bool     `json:"removed,omitempty"`
	ProcLinks     []string `json:"proclinks,omitempty"`
	TxId          string   `json:"txid,omitempty"`
	AppConfigJson string   `json:"appconfig"` // json-string

Represents the metadata for a "file" in the Dashborg FS. Returned from DashFSClient.FileInfo() or DashFSClient.DirInfo().

func (*FileInfo) BindMetadata added in v0.7.0

func (finfo *FileInfo) BindMetadata(obj interface{}) error

Unmarshals the FileInfo's metadata into an object (like json.Unmarshal).

func (*FileInfo) IsLinkType added in v0.7.1

func (finfo *FileInfo) IsLinkType() bool

Returns true if this FileInfo is a RuntimeLink or AppRuntimeLink (can have an attached Runtime).

type FileOpts added in v0.7.0

type FileOpts struct {
	FileType      string   `json:"filetype"`
	Sha256        string   `json:"sha256"`
	Size          int64    `json:"size"`
	MimeType      string   `json:"mimetype"`
	AllowedRoles  []string `json:"allowedroles,omitempty"`
	EditRoles     []string `json:"editroles,omitempty"`
	Display       string   `json:"display,omitempty"`
	MetadataJson  string   `json:"metadata,omitempty"`
	Description   string   `json:"description,omitempty"`
	NoMkDirs      bool     `json:"nomkdirs,omitempty"`
	Hidden        bool     `json:"hidden,omitempty"`
	AppConfigJson string   `json:"appconfig"` // json-string

Options that set or update a new file's FileInfo metadata. Not all options are required for all file types.

func (*FileOpts) IsLinkType added in v0.7.0

func (opts *FileOpts) IsLinkType() bool

Returns true if this FileOpts is a RuntimeLink or AppRuntimeLink (can have an attached Runtime).

func (*FileOpts) SetMetadata added in v0.7.0

func (opts *FileOpts) SetMetadata(obj interface{}) error

Marshals (json.Marshal) an object to the FileInfo.Metadata field.

func (*FileOpts) Validate added in v0.7.0

func (opts *FileOpts) Validate() error

type HandlerOpts added in v0.7.0

type HandlerOpts struct {
	Hidden         bool
	PureHandler    bool
	Display        string
	FormDisplay    string
	ResultsDisplay string

type HasErr added in v0.7.0

type HasErr interface {
	Err() error

type JWTOpts added in v0.7.0

type JWTOpts struct {
	NoJWT    bool
	ValidFor time.Duration
	UserId   string
	Role     string

func (*JWTOpts) Validate added in v0.7.0

func (jwtOpts *JWTOpts) Validate() error

type LinkRuntime added in v0.7.0

type LinkRuntime interface {
	RunHandler(req *AppRequest) (interface{}, error)

type LinkRuntimeImpl added in v0.7.0

type LinkRuntimeImpl struct {
	// contains filtered or unexported fields

func MakeRuntime added in v0.7.0

func MakeRuntime() *LinkRuntimeImpl

Creates a LinkRuntime structure.

func MakeSingleFnRuntime added in v0.7.0

func MakeSingleFnRuntime(handlerFn interface{}, opts ...*HandlerOpts) *LinkRuntimeImpl

Creates a LinkRuntime structure with a single function. This lets the handler act like a dynamic file. So if the application requests a path (without a fragment), the handlerFn can return the result.

func (*LinkRuntimeImpl) AddRawMiddleware added in v0.7.0

func (linkrt *LinkRuntimeImpl) AddRawMiddleware(name string, mwFunc MiddlewareFuncType, priority float64)

Adds a middleware function to this runtime.

func (*LinkRuntimeImpl) Err added in v0.7.0

func (linkrt *LinkRuntimeImpl) Err() error

Returns any setup errors that the runtime encountered.

func (*LinkRuntimeImpl) Handler added in v0.7.0

func (linkrt *LinkRuntimeImpl) Handler(name string, handlerFn interface{}, opts ...*HandlerOpts)

func (*LinkRuntimeImpl) PureHandler added in v0.7.0

func (linkrt *LinkRuntimeImpl) PureHandler(name string, handlerFn interface{}, opts ...*HandlerOpts)

func (*LinkRuntimeImpl) RemoveMiddleware added in v0.7.0

func (linkrt *LinkRuntimeImpl) RemoveMiddleware(name string)

Removes a middleware function from this runtime

func (*LinkRuntimeImpl) RunHandler added in v0.7.0

func (linkrt *LinkRuntimeImpl) RunHandler(req *AppRequest) (interface{}, error)

Runs an application handler given an AppRequest. This method is not normally used by end users, it is used by the Dashborg runtime to dispatch requests to this runtime.

func (*LinkRuntimeImpl) SetRawHandler added in v0.7.0

func (linkrt *LinkRuntimeImpl) SetRawHandler(handlerName string, handlerFn func(req Request) (interface{}, error), opts *HandlerOpts) error

Sets a raw handler. Normal code should use Handler() or PureHandler() which internally calls this method.

type MiddlewareFuncType added in v0.6.0

type MiddlewareFuncType func(req *AppRequest, nextFn MiddlewareNextFuncType) (interface{}, error)

type MiddlewareNextFuncType added in v0.6.0

type MiddlewareNextFuncType func(req *AppRequest) (interface{}, error)

type ProcInfo added in v0.6.0

type ProcInfo struct {
	StartTs   int64
	ProcRunId string
	ProcName  string
	ProcTags  map[string]string
	HostData  map[string]string

type RawRequestData added in v0.6.0

type RawRequestData struct {
	DataJson     string
	AppStateJson string
	AuthDataJson string

type ReflectProcType added in v0.7.0

type ReflectProcType struct {
	StartTs   int64             `json:"startts"`
	ProcName  string            `json:"procname"`
	ProcIKey  string            `json:"procikey"`
	ProcTags  map[string]string `json:"proctags"`
	ProcRunId string            `json:"procrunid"`

type Request added in v0.6.0

type Request interface {
	Context() context.Context
	AuthData() *AuthAtom
	RequestInfo() RequestInfo
	RawData() RawRequestData
	BindData(obj interface{}) error
	BindAppState(obj interface{}) error

For LinkRuntime requests and PureRequets, those functions get a Request interface not an *AppRequest. Pure requests cannot call SetData, NavTo, etc. or any method that would cause side effects for the application UI outside of the return value.

type RequestInfo added in v0.6.0

type RequestInfo struct {
	StartTime     time.Time
	ReqId         string // unique request id
	RequestType   string // "data", "handler", or "stream"
	RequestMethod string // GET or POST
	Path          string // request path
	AppName       string // app name
	FeClientId    string // unique id for client

type WatchOpts added in v0.7.0

type WatchOpts struct {
	ThrottleTime time.Duration
	ShutdownCh   chan struct{}

Options to pass to DashFSClient.WatchFile(). Controls how fsnotify watches the given file.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL