Documentation ¶
Index ¶
- Constants
- Variables
- func NewNotifyPackCreate(containerID string, comp Component) *notifyPackCreate
- func NewNotifyPackDelete(compID string) *notifyPackDelete
- func NewNotifyPackUpdate(comp Component) *notifyPackUpdate
- type App
- func (app *App) AddPage(name, title string, runFunc RunFunc)
- func (app *App) AddPageByConfig(conf *PageConfig, runFunc RunFunc)
- func (app *App) AppConf() *AppConf
- func (app *App) FirstPage() (string, bool)
- func (app *App) HasPage(name string) bool
- func (app *App) Run(name string, state *State, notifyFunc SendNotifyPackFunc) error
- func (app *App) RunWithHandlingPanic(name string, state *State, notifyFunc SendNotifyPackFunc) (err error)
- func (app *App) SetHashPageNameMode(v bool)
- type AppConf
- type BaseComponent
- type Component
- type Container
- type Event
- type EventClick
- type EventEmpty
- type EventForm
- type EventInput
- type EventSelect
- type EventStruct
- type EventType
- type NotifyPack
- type PageConfig
- type Params
- type RunFunc
- type SendNotifyPackFunc
- type State
- func (s *State) Clone() *State
- func (s *State) Default(key string, v any) any
- func (s *State) Destroy()
- func (s *State) GetBool(key string) bool
- func (s *State) GetClickID() string
- func (s *State) GetFile(key string) []byte
- func (s *State) GetFloat(key string) *float64
- func (s *State) GetFuncCache(key string) any
- func (s *State) GetFuncCacheWithFuncName(key string, funcName string) any
- func (s *State) GetInt(key string) *int
- func (s *State) GetObject(key string, out any) error
- func (s *State) GetString(key string) *string
- func (s *State) Set(key string, v any)
- func (s *State) SetClickID(id string)
- func (s *State) SetFile(key string, bs []byte)
- func (s *State) SetFuncCache(key string, value any)
- func (s *State) SetFuncCacheWithFuncName(key string, value any, funcName string)
Constants ¶
const ( NotifyTypeCreate = 1 NotifyTypeUpdate = 2 NotifyTypeDelete = 3 )
const MainContainerID string = "container_main"
MainContainerID is the id of root container. The creation of root container won't trigger SendNotifyPackFunc.
const SidebarContainerID string = "container_sidebar"
SidebarContainerID is the id of sidebar container. The creation of root container won't trigger SendNotifyPackFunc.
Variables ¶
var ContainerComponentName = "container_component"
var ErrPageNotFound = errors.New("page not found")
ErrPageNotFound is the error that the page is not found.
var ErrPanic = errors.New("panic")
ErrPanic is the error that the app panics.
Functions ¶
func NewNotifyPackCreate ¶
NewNotifyPackCreate creates a new notify pack for creating a component.
func NewNotifyPackDelete ¶
func NewNotifyPackDelete(compID string) *notifyPackDelete
NewNotifyPackDelete creates a new notify pack for deleting a component.
func NewNotifyPackUpdate ¶
func NewNotifyPackUpdate(comp Component) *notifyPackUpdate
NewNotifyPackUpdate creates a new notify pack for updating a component.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App is an app
func (*App) AddPage ¶
AddPage add a handled page by name, title, and runFunc.
app.AddPage("index", "Index", f})
func (*App) AddPageByConfig ¶
func (app *App) AddPageByConfig(conf *PageConfig, runFunc RunFunc)
AddPageByConfig add a handled page by name, title, icon, and runFunc.
app.AddPageByConfig(&tgframe.PageConfig{ Name: "page1", Title: "Page1", Emoji: "🐱", }, Page1)
func (*App) Run ¶
func (app *App) Run(name string, state *State, notifyFunc SendNotifyPackFunc) error
Run run a page which named `name` with state.
func (*App) RunWithHandlingPanic ¶
func (app *App) RunWithHandlingPanic( name string, state *State, notifyFunc SendNotifyPackFunc) (err error)
Run run a page which named `name` with state. Return a error wrap with ErrPanic if encounter panic.
func (*App) SetHashPageNameMode ¶
SetHashPageMode set value of hash page name mode flag.
type AppConf ¶
type AppConf struct { PageNames []string `json:"page_names"` PageConfs map[string]*PageConfig `json:"page_confs"` HashPageNameMode bool `json:"hash_page_name_mode"` MainContainerID string `json:"main_container_id"` SidebarContainerID string `json:"sidebar_container_id"` }
AppConf store configs for frontend
type BaseComponent ¶
type BaseComponent struct { // Name is the typename of the component. Name string `json:"name"` // ID shouldn't be duplicated. ID string `json:"id"` }
BaseComponent stores the basic info of a component.
type Component ¶
type Component interface {
GetID() string
}
Component is the interface of a component.
type Container ¶
type Container struct { *BaseComponent SendNotifyPack SendNotifyPackFunc `json:"-"` }
Container contain list of components.
func NewContainer ¶
func NewContainer(id string, notifyComp SendNotifyPackFunc) *Container
func (*Container) AddComponent ¶
func (*Container) AddContainer ¶
type Event ¶ added in v0.2.2
type Event interface {
ApplyState(state *State)
}
Event is the state change made by app user
func ParseEvent ¶ added in v0.2.2
type EventClick ¶ added in v0.2.2
type EventClick struct {
ID string `json:"id"`
}
EventClick is the event of a button click event
func (*EventClick) ApplyState ¶ added in v0.2.2
func (e *EventClick) ApplyState(state *State)
type EventEmpty ¶ added in v0.2.2
type EventEmpty struct { }
EventEmpty is the event of an empty event, rerun button will send this
func (*EventEmpty) ApplyState ¶ added in v0.2.2
func (e *EventEmpty) ApplyState(*State)
type EventForm ¶ added in v0.2.2
type EventForm struct {
Events []Event `json:"events"`
}
EventForm is the event of a form event it's used for form component
func (*EventForm) ApplyState ¶ added in v0.2.2
type EventInput ¶ added in v0.2.2
EventInput is the event of a input event it's used for all input components
func (*EventInput) ApplyState ¶ added in v0.2.2
func (e *EventInput) ApplyState(state *State)
type EventSelect ¶ added in v0.2.2
EventSelect is the event of a select event it's used for select/radio component
func (*EventSelect) ApplyState ¶ added in v0.2.2
func (e *EventSelect) ApplyState(state *State)
type EventStruct ¶ added in v0.2.2
type EventStruct struct {
Type EventType `json:"type"`
}
type NotifyPack ¶
type NotifyPack interface {
GetType() int
}
NotifyPack is the interface that notify packs must implement.
type PageConfig ¶
type PageConfig struct { // Name should not duplicate to another page Name string `json:"name"` // Title will show as the title of page Title string `json:"title"` // Emoji will show as icon of a page Emoji string `json:"emoji"` }
PageConfig stores basic setting of a page
type SendNotifyPackFunc ¶
type SendNotifyPackFunc func(NotifyPack)
SendNotifyPackFunc is the function type that sends a notify pack to the GUI client.
type State ¶
type State struct {
// contains filtered or unexported fields
}
State is the state of a user's session.
func (*State) Default ¶
Default sets the value of a key if the key is not set. If the key is set, it returns the value. If the key is not set, it sets the value and returns the value. The v should be a pointer. Example: ```go
type TODOList struct { Items []string `json:"items"` } todoList := state.Default("todoList", &TODOList{}).(*TODOList)
```
func (*State) GetClickID ¶
GetClickID get the id of clicked button.
func (*State) GetFloat ¶ added in v0.2.1
GetFloat gets the value of a key and returns it as a float64.
func (*State) GetFuncCache ¶
GetFuncCache gets the value of a key in the function cache.
func (*State) GetFuncCacheWithFuncName ¶
GetFuncCacheWithFuncName gets the value of a key in the function cache with a specific function name.
func (*State) GetInt ¶
GetInt gets the value of a key and returns it as an int. If the key is not set, it returns nil.
func (*State) SetClickID ¶
SetClickID set the id of clicked button.
func (*State) SetFuncCache ¶
SetFuncCache sets the value of a key in the function cache.