tree

package
v0.0.0-...-84bb75c Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Db *gorm.DB
View Source
var JwtKey []byte
View Source
var LogLevel = new(slog.LevelVar)
View Source
var LogLevelNames = map[string]slog.Level{
	"info":  slog.LevelInfo,
	"debug": slog.LevelDebug,
	"warn":  slog.LevelWarn,
	"error": slog.LevelError,
}
View Source
var MKNames = map[MK]string{
	M_OK:    "OK",
	M_Error: "Error",

	M_Create: "Create",
	M_Rename: "Rename",
	M_Delete: "Delete",

	M_Get_Parms:   "Get_Parms",
	M_Get_Auth:    "Get_Auth",
	M_Get_Tree:    "Get_Tree",
	M_Get_Display: "Get_Display",
	M_Get_Child:   "Get_Child",

	M_Update_Parms: "Update_Parms",

	M_Refresh_Node: "Refresh_Node",
	M_Refresh_Tree: "Refresh_Tree",

	M_Subscribe:   "Subscribe",
	M_Unsubscribe: "Unsubscribe",

	M_Stop: "Stop",

	M_UpdatePath: "UpdatePath",
}

MNames is exported for logging purposes.

View Source
var NKNames = map[NK]string{
	NK_Root:        "Root",
	NK_Group:       "Group",
	NK_User:        "User",
	NK_Account:     "Account",
	NK_Trader:      "Broker",
	NK_TreeUpdater: "TreeUpdater",
	NK_Users:       "Users",
	NK_GUI:         "GUI",
}

TODO: We need to rename this to NNames.

View Source
var SystemUser = &Tag{0, NK_User, nil, true, nil, nil}

System user is a special user that can do anything.

View Source
var Tree = nodeTree{
	// contains filtered or unexported fields
}

Functions

func AskJSON

func AskJSON(tid, uid NodeID, mk MK, plr io.ReadCloser) (pl any, err error)

func CloseDB

func CloseDB() (err error)

func CreateUser

func CreateUser(nm, email, pwd string) error

func FileExists

func FileExists(fn string) bool

func GenerateSecret

func GenerateSecret(l int) ([]byte, error)

func InitTree

func InitTree(sdb string, rp RootParms) (err error)

func RunGUIClient

func RunGUIClient(uid NodeID, c *websocket.Conn) (err error)

func Stop

func Stop() (err error)

Types

type DC

type DC chan E

type E

type E struct{}

type GUINode

type GUINode struct {
	*Head
	// contains filtered or unexported fields
}

type GroupNode

type GroupNode struct {
	*Head
}

type H

type H = map[string]any

type HF

type HF func(Node, *Msg) *Msg

Message handler function

type Head struct {
	*Tag
	ParentID  NodeID // This is only used for database storage.
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt `gorm:"index"`

	Name string
	// contains filtered or unexported fields
}

type MK

type MK = int
const (
	M_OK MK = iota
	M_Error

	M_Create
	M_Rename
	M_Delete

	M_Get_Parms
	M_Get_Auth
	M_Get_Tree
	M_Get_Display
	M_Get_Child

	M_Update_Parms

	M_Refresh_Node
	M_Refresh_Tree

	M_Subscribe
	M_Unsubscribe

	M_Stop

	M_UpdatePath
)

type Msg

type Msg struct {
	Kind    MK
	User    *Tag
	Payload any
	// contains filtered or unexported fields
}

func NewErrorMsg

func NewErrorMsg(err error) *Msg

func (*Msg) Answer

func (q *Msg) Answer(mk MK, pl ...any)

func (*Msg) AnswerMsg

func (q *Msg) AnswerMsg(a *Msg)

func (*Msg) AnswerOK

func (q *Msg) AnswerOK()

func (*Msg) KindName

func (m *Msg) KindName() string

type NK

type NK int
const (
	NK_Root NK = iota
	NK_Group
	NK_User
	NK_Account
	NK_Trader
	NK_TreeUpdater
	NK_Users
	NK_GUI

	NK_Noop
)

type Node

type Node interface {
	// contains filtered or unexported methods
}

type NodeID

type NodeID = int

func AuthUser

func AuthUser(nm, pwd string) (uid NodeID, admin bool, err error)

func NextID

func NextID() NodeID

type ParmModel

type ParmModel struct {
	ID        int `gorm:"primarykey"`
	CreatedAt time.Time
	HeadID    NodeID
}

type Pipe

type Pipe chan *Msg

func (Pipe) MarshalJSON

func (p Pipe) MarshalJSON() ([]byte, error)

type RootNode

type RootNode struct {
	*Head
	Parms *RootParms
}

type RootParms

type RootParms struct {
	ParmModel
	LogLevel int
	HTTPAddr string
	DbKey    string
	JwtKey   []byte
}

func GetServerParms

func GetServerParms() (rp RootParms, err error)

type SK

type SK int

Service kind

const (
	SK_Node_Updates SK = iota
	SK_Tree_Updates
)

type Tag

type Tag struct {
	ID     NodeID `gorm:"primarykey"`
	Kind   NK
	In     Pipe `gorm:"-"`
	Admin  bool `gorm:"-"`
	Parent *Tag `gorm:"-"`
	Owner  *Tag `gorm:"-"`
}

func (*Tag) Ask

func (t *Tag) Ask(u *Tag, mk MK, pl ...any) *Msg

func (*Tag) AskMsg

func (t *Tag) AskMsg(m *Msg) Msg

func (*Tag) Notify

func (t *Tag) Notify(u *Tag, mk MK, pl ...any)

func (*Tag) NotifyMsg

func (t *Tag) NotifyMsg(m *Msg)

type TreeEntry

type TreeEntry struct {
	ID       NodeID
	Name     string
	Kind     NK
	Children []*TreeEntry `json:",omitempty"`
}

type TreeUpdaterNode

type TreeUpdaterNode struct {
	*Head
	// contains filtered or unexported fields
}

type UserNode

type UserNode struct {
	*Head
	Parms *UserParms
}

type UserParms

type UserParms struct {
	ParmModel
	Admin    bool
	Email    string
	Password []byte
}

type UsersNode

type UsersNode struct {
	*Head
	Parms *UsersParms
}

type UsersParms

type UsersParms struct {
	ParmModel
	InvitationOnly bool
}

type WSMK

type WSMK int
const (
	WSM_Credentials WSMK = iota
	WSM_Subscribe
	WSM_Unsubscribe
	WSM_Update
	WSM_Error
	WSM_ClientShutdown
	WSM_Heartbeat
	WSM_Renamed
	WSM_Created
	WSM_Deleted
)

WsMsgKind is the kind of message sent over the websocket

Jump to

Keyboard shortcuts

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