Version: v0.6.1 Latest Latest

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

Go to latest
Published: Aug 26, 2021 License: MIT Imports: 21 Imported by: 0




View Source
const (
	RoleSuper  = "*"
	RolePublic = "public"
	RoleUser   = "user"
View Source
const (
	AccTypeAnon       = "anon"
	AccTypeFree       = "free"
	AccTypePro        = "pro"
	AccTypeEnterprise = "enterprise"
View Source
const (
	OptionInitHandler   = "inithandler"
	OptionHtml          = "html"
	OptionAuth          = "auth"
	OptionOfflineMode   = "offlinemode"
	OptionTitle         = "title"
	OptionAppVisibility = "visibility"

	AuthTypeZone = "zone"

	VisTypeHidden        = "hidden"  // always hide
	VisTypeDefault       = "default" // shown if user has permission
	VisTypeAlwaysVisible = "visible" // always show

	HtmlTypeStatic               = "static"
	HtmlTypeDynamicWhenConnected = "dynamic-when-connected"
	HtmlTypeDynamic              = "dynamic"

	InitHandlerRequired              = "required"
	InitHandlerRequiredWhenConnected = "required-when-connected"
	InitHandlerNone                  = "none"

	OfflineModeEnable  = "enable"
	OfflineModeDisable = "disable"
View Source
const AuthScopeZone = "zone"
View Source
const ClientVersion = "go-0.6.0"
View Source
const MaxAppConfigSize = 10000
View Source
const MaxAuthExp = 24 * time.Hour
View Source
const RtnSetDataPath = "@rtn"


This section is empty.


This section is empty.


type App added in v0.6.0

type App struct {
	// contains filtered or unexported fields

func MakeApp added in v0.6.0

func MakeApp(appName string, api InternalApi) *App

func MakeAppFromConfig added in v0.6.0

func MakeAppFromConfig(cfg AppConfig, api InternalApi) *App

func (*App) AppConfig added in v0.6.0

func (app *App) AppConfig() AppConfig

func (*App) AppName added in v0.6.0

func (app *App) AppName() string

func (*App) Blobs added in v0.6.0

func (app *App) Blobs() BlobManager

func (*App) IsNew added in v0.6.0

func (app *App) IsNew() bool

func (*App) RawOptionRemove added in v0.6.0

func (app *App) RawOptionRemove(optName string)

func (*App) RawOptionSet added in v0.6.0

func (app *App) RawOptionSet(optName string, opt GenericAppOption)

func (*App) Runtime added in v0.6.0

func (app *App) Runtime() *AppRuntimeImpl

func (*App) SetAllowedRoles added in v0.6.0

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

func (*App) SetAppTitle added in v0.6.0

func (app *App) SetAppTitle(title string)

func (*App) SetAppVisibility added in v0.6.0

func (app *App) SetAppVisibility(visType string, displayOrder 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) SetAuthType added in v0.6.0

func (app *App) SetAuthType(authType string)

authType must be AuthTypeZone

func (*App) SetHtml added in v0.6.0

func (app *App) SetHtml(htmlStr string) error

func (*App) SetHtmlFromFile added in v0.6.0

func (app *App) SetHtmlFromFile(fileName string) error

func (*App) SetInitHandlerType added in v0.6.0

func (app *App) SetInitHandlerType(initType string)

initType is either InitHandlerRequired, InitHandlerRequiredWhenConnected, or InitHandlerNone

func (*App) SetOfflineModeType added in v0.6.0

func (app *App) SetOfflineModeType(offlineModeType string)

offline mode type is either OfflineModeEnable or OfflineModeDisable

type AppClient added in v0.6.0

type AppClient interface {
	DispatchRequest(ctx context.Context, reqMsg *dashproto.RequestMessage)
	SendRequestResponse(req *Request, done bool) (int, error)
	StartStream(appName string, streamOpts StreamOpts, feClientId string) (*Request, string, error)

internal interface (for communication with Dashborg Cloud Service) API is not stable

func MakeAppClient added in v0.6.0

func MakeAppClient(api InternalApi, app AppRuntime, config AppClientConfig, connId *atomic.Value) AppClient

type AppClientConfig added in v0.6.0

type AppClientConfig struct {
	Verbose bool

type AppConfig added in v0.6.0

type AppConfig struct {
	AppName            string                      `json:"appname"`
	AppVersion         string                      `json:"appversion,omitempty"` // uuid
	UpdatedTs          int64                       `json:"updatedts"`            // set by container
	ProcRunId          string                      `json:"procrunid"`            // set by container
	ClientVersion      string                      `json:"clientversion"`
	Options            map[string]GenericAppOption `json:"options"`
	ClearExistingBlobs bool                        `json:"clearexistingblobs,omitempty"`

AppConfig is passed as JSON to the container. this struct helps with marshaling/unmarshaling the structure.

type AppId added in v0.6.0

type AppId struct {
	AppName    string
	AppVersion string

type AppRuntime added in v0.6.0

type AppRuntime interface {
	AppName() string
	RunHandler(req *Request) (interface{}, error)

type AppRuntimeImpl added in v0.6.0

type AppRuntimeImpl struct {
	// contains filtered or unexported fields

func MakeAppRuntime added in v0.6.0

func MakeAppRuntime(appName string) *AppRuntimeImpl

Apps that are created using dashcloud.OpenApp() have their own built in runtime. Only call MakeAppRuntime when you want to call dashcloud.ConnectAppRuntime() without calling OpenApp.

func (*AppRuntimeImpl) AddRawMiddleware added in v0.6.0

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

func (*AppRuntimeImpl) AppName added in v0.6.0

func (apprt *AppRuntimeImpl) AppName() string

func (*AppRuntimeImpl) Handler added in v0.6.0

func (apprt *AppRuntimeImpl) Handler(path string, handlerFn interface{}) error

HandlerEx 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.Request. 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) RemoveMiddleware added in v0.6.0

func (apprt *AppRuntimeImpl) RemoveMiddleware(name string)

func (*AppRuntimeImpl) RunHandler added in v0.6.0

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

func (*AppRuntimeImpl) SetAppStateType added in v0.6.0

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

func (*AppRuntimeImpl) SetInitHandler added in v0.6.0

func (apprt *AppRuntimeImpl) SetInitHandler(handlerFn func(req *Request) error) error

func (*AppRuntimeImpl) SetRawHandler added in v0.6.0

func (apprt *AppRuntimeImpl) SetRawHandler(path string, handlerFn func(req *Request) (interface{}, error)) error

type AuthAtom added in v0.6.0

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

func (*AuthAtom) GetRole added in v0.6.0

func (aa *AuthAtom) GetRole() string

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

type BlobData added in v0.6.0

type BlobData struct {
	BlobNs   string      `json:"blobns"`
	BlobKey  string      `json:"blobkey"`
	MimeType string      `json:"mimetype"`
	Size     int64       `json:"size"`
	Sha256   string      `json:"sha256"`
	UpdateTs int64       `json:"updatets"`
	Metadata interface{} `json:"metadata"`
	Removed  bool        `json:"removed"`
	Added    bool        `json:"added"`

func BlobDataFromReadSeeker added in v0.6.0

func BlobDataFromReadSeeker(extBlobKey string, mimeType string, r io.ReadSeeker) (BlobData, 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)

func BlobDataFromReader added in v0.6.0

func BlobDataFromReader(extBlobKey string, mimeType string, r io.Reader) (BlobData, *bytes.Reader, error)

If you only have an io.Reader, this function will call ioutil.ReadAll, read the full stream into a []byte, compute the size and SHA-256, and then wrap the []byte in a *bytes.Reader suitable to pass to SetRawBlobData()

func (BlobData) ExtBlobKey added in v0.6.0

func (b BlobData) ExtBlobKey() string

type BlobManager added in v0.6.0

type BlobManager interface {
	SetRawBlobData(blobData BlobData, reader io.Reader) error
	SetJsonBlob(extBlobKey string, data interface{}, metadata interface{}) error
	SetBlobDataFromFile(key string, mimeType string, fileName string, metadata interface{}) error
	RemoveBlob(extBlobKey string) error
	ListBlobs() ([]BlobData, error)

type CallHandlerOpts added in v0.6.0

type CallHandlerOpts struct {
	StateType reflect.Type

type GenericAppOption added in v0.6.0

type GenericAppOption struct {
	Type         string   `json:"type,omitempty"`
	Path         string   `json:"path,omitempty"`
	AllowedRoles []string `json:"allowedroles,omitempty"`
	Enabled      bool     `json:"enabled,omitempty"`
	AppTitle     string   `json:"apptitle,omitempty"`
	Order        float64  `json:"order,omitempty"`

super-set of all option fields for JSON marshaling/parsing

type InternalApi added in v0.6.0

type InternalApi interface {
	// StartBareStream(appName string, streamOpts StreamOpts) (*Request, error)
	// BackendPush(appName string, path string, data interface{}) error
	SetBlobData(acfg AppConfig, blob BlobData, r io.Reader) error
	RemoveBlob(acfg AppConfig, blob BlobData) error
	ListBlobs(appName string, appVersion string) ([]BlobData, error)
	SendResponseProtoRpc(m *dashproto.SendResponseMessage) (int, error)
	StartStreamProtoRpc(m *dashproto.StartStreamMessage) (string, error)

internal callbacks into DashCloud package. Not for use by end-user, API subject to change.

type MiddlewareFuncType added in v0.6.0

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

type MiddlewareNextFuncType added in v0.6.0

type MiddlewareNextFuncType func(req *Request) (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 Request added in v0.6.0

type Request struct {
	// contains filtered or unexported fields

func (*Request) AppState added in v0.6.0

func (req *Request) AppState() interface{}

func (*Request) AuthData added in v0.6.0

func (req *Request) AuthData() *AuthAtom

func (*Request) BindAppState added in v0.6.0

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

func (*Request) BindData added in v0.6.0

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

func (*Request) Context added in v0.6.0

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

func (*Request) DataOp added in v0.6.0

func (req *Request) DataOp(op string, path string, data interface{}) error

SetData is used to return data to the client. Will replace the contents of path with data.

func (*Request) Done added in v0.6.0

func (req *Request) Done() error

Done() ends a request and sends the results back to the client. It is automatically called after a handler is run. Only needs to be called explicitly if you'd like to return your result earlier, or for bare stream requests.

func (*Request) Flush added in v0.6.0

func (req *Request) Flush() error

func (*Request) InvalidateData added in v0.6.0

func (req *Request) 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. (e.g. use InvalidateData(".*") to invalidate all data).

func (*Request) IsDone added in v0.6.0

func (req *Request) IsDone() bool

func (*Request) RawData added in v0.6.0

func (req *Request) RawData() RawRequestData

func (*Request) RequestInfo added in v0.6.0

func (req *Request) RequestInfo() RequestInfo

func (*Request) SetBlob added in v0.6.0

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

SetBlobData sends blob data to the server. Note that SetBlob will flush any pending actions to the server

func (*Request) SetBlobFromFile added in v0.6.0

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

func (*Request) SetData added in v0.6.0

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

SetData is used to return data to the client. Will replace the contents of path with data.

func (*Request) StartStream added in v0.6.0

func (req *Request) StartStream(streamOpts StreamOpts, streamFn func(req *Request)) error

StartStream creates a new streaming request that can send data to the original request's client. streamId is used to control whether a new stream will be created or if the client will attach to an existing stream. The streamFn gets passed a context that is used for cancelation. Note that StartStream will flush any pending actions to the server. If the stream already exists, the existing StreamOpts will not change (keeps the old NoServerCancel setting). streamFn may be nil (useful if you are intending to attach to an existing stream created with StartBareStream).

func (*Request) UrlParams added in v0.6.0

func (req *Request) UrlParams() url.Values

type RequestInfo added in v0.6.0

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

type StreamOpts added in v0.4.2

type StreamOpts struct {
	StreamId       string `json:"streamid"`       // if unset will be set to a random uuid
	ControlPath    string `json:"controlpath"`    // control path for client cancelation
	NoServerCancel bool   `json:"noservercancel"` // set to true to keep running the stream, even when there are no clients listening (or on server error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL