db

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Database

user - store user special attributes, such as non-ldap user, groups node - store gateway nodes participating in the mesh

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database interface {
	// migrate database schema
	Migrate(context.Context) error

	// close opened database
	Close() error

	ListUsers(context.Context) ([]*User, error)
	ListOnlineUsers(context.Context, time.Time) ([]*User, error)
	MarkUsersOnline(context.Context, []string, string, time.Duration) error
	ClearUserNodeID(context.Context, string, string) error
	GetUser(context.Context, string) (*User, error)
	PutUser(context.Context, string, func(*User) error) (*User, error)

	ListNodes(context.Context) ([]*Node, error)
	GetNode(context.Context, string) (*Node, error)
	PutNode(context.Context, string, func(*Node) error) (*Node, error)
}

func Open

func Open(settings *Settings) (Database, error)

type Location

type Location struct {
	Latitude  float64 `json:"latitude,omitempty"`
	Longitude float64 `json:"longitude,omitempty"`
	TimeZone  string  `json:"timezone,omitempty"`
	Country   string  `json:"country,omitempty"`
	City      string  `json:"city,omitempty"`
}

shared location info

func (*Location) Scan

func (self *Location) Scan(value interface{}) error

func (Location) Value

func (self Location) Value() (driver.Value, error)

type Node added in v0.5.0

type Node struct {
	ID string `json:"id,omitempty" gorm:"primary_key:true"`

	// meta data
	CreatedAt  time.Time `json:"createdAt,omitempty"`
	ModifiedAt time.Time `json:"modifiedAt,omitempty"`

	// address where peer nodes can reach this node
	Address string `json:"address,omitempty"`

	// host public key of this node in authorized key format, pinned by
	// dialing peers to verify the remote host
	HostPublicKey string `json:"hostPublicKey,omitempty"`

	// whether the node is online; cleared on clean shutdown, but a crashed
	// node leaves it set, so liveness also requires a fresh OnlineAt
	Online bool `json:"online,omitempty"`

	// the last online heartbeat, refreshed while the node is running, so a
	// stale value marks a node that went away without marking itself offline
	OnlineAt time.Time `json:"onlineAt,omitempty"`
}

represents a gateway node participating in the mesh

func (*Node) TableName added in v0.5.0

func (self *Node) TableName() string

type Settings added in v0.5.0

type Settings struct {
	// postgres connection settings
	Host         string
	Port         uint16
	User         string
	Password     string
	DatabaseName string
	SSLMode      string

	// optional peer tunnel settings, for reaching a remote postgres through
	// a peer node's ssh service port instead of connecting directly
	PeerAddress       string        // peer ssh address, empty = direct connection
	PeerSigner        ssh.Signer    // node certificate signer, required if PeerAddress is set
	PeerHostPublicKey ssh.PublicKey // pinned host public key of the peer, required if PeerAddress is set
}

type Status

type Status json.RawMessage

func (Status) MarshalJSON

func (self Status) MarshalJSON() ([]byte, error)

func (*Status) Scan

func (self *Status) Scan(value interface{}) error

func (Status) Value

func (self Status) Value() (driver.Value, error)

type User

type User struct {
	ID string `json:"id,omitempty" gorm:"primary_key:true"`

	// meta data
	CreatedAt  time.Time `json:"createdAt,omitempty"`
	ModifiedAt time.Time `json:"modifiedAt,omitempty"`

	// comments about this user
	Comment string `json:"comment,omitempty"`

	// ip address
	IP string `json:"ip,omitempty"`

	// geo location
	Location Location `json:"location,omitempty" gorm:"type:jsonb"`

	// reported status
	Status Status `json:"status,omitempty"`

	// whether the user is an administrator
	Administrator bool `json:"administrator,omitempty"`

	// screenshot
	Screenshot []byte `json:"-" gorm:"type:bytea"`

	// whether the user account has been disabled
	Disabled bool `json:"disabled,omitempty"`

	// the node the user last connected to, used for mesh tunneling
	NodeID string `json:"nodeId,omitempty"`

	// the last time the user was seen connected on any node; refreshed on a
	// heartbeat while connected, so a fresh value means online mesh-wide
	OnlineAt time.Time `json:"onlineAt,omitempty"`

	// whether the user is online, derived from OnlineAt, not saved in database
	Online bool `json:"online,omitempty" gorm:"-"`

	// current connections, not saved in database
	Connections interface{} `json:"connections,omitempty" gorm:"-"`
}

represents a user connected to gateway

func (*User) TableName

func (self *User) TableName() string

Directories

Path Synopsis
Package dbtest provides helpers for database integration tests.
Package dbtest provides helpers for database integration tests.

Jump to

Keyboard shortcuts

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