### Client Start Method Source: https://pkg.go.dev/stdchat.org/service/dummy Starts the client's network operations within a given context and ID. ```go func (client *Client) Start(ctx context.Context, id string) error ``` -------------------------------- ### ListenAndServe Source: https://pkg.go.dev/stdchat.org/provider Starts a service provider and listens for incoming connections using the provided options, service, and transport. ```APIDOC ## ListenAndServe ### Description Starts a service provider and listens for incoming connections using the provided options, service, and transport. ### Signature ```go func ListenAndServe(opts Options, svc service.Servicer, tp service.MultiTransporter) error ``` ### Parameters - **opts** (Options) - Configuration options for the provider. - **svc** (service.Servicer) - The service implementation to serve. - **tp** (service.MultiTransporter) - The transport layer for the service. ``` -------------------------------- ### ListenAndServe Function Signature Source: https://pkg.go.dev/stdchat.org/provider ListenAndServe starts a service provider with specified options, a service implementation, and a multi-transporter. ```go func ListenAndServe(opts Options, svc service.Servicer, tp service.MultiTransporter) error ``` -------------------------------- ### Get Name from MediaInfo Source: https://pkg.go.dev/stdchat.org Retrieves the name for MediaInfo. ```go func (x MediaInfo) GetName() string ``` -------------------------------- ### String method for ProtocolStateInfo Source: https://pkg.go.dev/stdchat.org Method to get a string representation of ProtocolStateInfo. ```go func (x ProtocolStateInfo) String() string ``` -------------------------------- ### String method for SubscriptionStateInfo Source: https://pkg.go.dev/stdchat.org Method to get a string representation of SubscriptionStateInfo. ```go func (x SubscriptionStateInfo) String() string ``` -------------------------------- ### Get Service Protocol Source: https://pkg.go.dev/stdchat.org/service Returns the protocol string associated with the service. ```go func (svc *Service) Protocol() string ``` -------------------------------- ### Map type methods Source: https://pkg.go.dev/expvar Provides Delete, Do, Get, Init, and String methods for the Map type, in addition to Add and Set. ```go func (v *Map) Delete(key string) ``` ```go func (v *Map) Do(f func(KeyValue)) ``` ```go func (v *Map) Get(key string) Var ``` ```go func (v *Map) Init() *Map ``` ```go func (v *Map) String() string ``` -------------------------------- ### String method for NetworkStateInfo Source: https://pkg.go.dev/stdchat.org Method to get a string representation of NetworkStateInfo. ```go func (x NetworkStateInfo) String() string ``` -------------------------------- ### Get Service Context Source: https://pkg.go.dev/stdchat.org/service Retrieves the context associated with the service. ```go func (svc *Service) Context() context.Context ``` -------------------------------- ### Get the expvar HTTP handler Source: https://pkg.go.dev/expvar Handler returns the expvar HTTP handler. This is useful for installing the handler at a non-standard URL path. ```go func Handler() http.Handler ``` -------------------------------- ### Get Key from KeyValueInfo Source: https://pkg.go.dev/stdchat.org Returns the key from a KeyValueInfo pair. ```go func (kvi KeyValueInfo) Key() string ``` -------------------------------- ### Get Value from KeyValueInfo Source: https://pkg.go.dev/stdchat.org Returns the value from a KeyValueInfo pair. ```go func (kvi KeyValueInfo) Value() string ``` -------------------------------- ### MultiTransport.GetProtocol Source: https://pkg.go.dev/stdchat.org/service Gets the protocol string of the multi-transport. ```APIDOC ## MultiTransport.GetProtocol ### Description Gets the protocol string of the multi-transport. ### Method Signature ```go func (tp *MultiTransport) GetProtocol() string ``` ``` -------------------------------- ### Get ID from MediaInfo Source: https://pkg.go.dev/stdchat.org Retrieves the ID for MediaInfo. ```go func (x MediaInfo) GetID() string ``` -------------------------------- ### Get Display Name from MediaInfo Source: https://pkg.go.dev/stdchat.org Retrieves the display name for MediaInfo. ```go func (x MediaInfo) GetDisplayName() string ``` -------------------------------- ### LocalTransport.GetProtocol Source: https://pkg.go.dev/stdchat.org/service Gets the protocol string of the local transport. ```APIDOC ## LocalTransport.GetProtocol ### Description Gets the protocol string of the local transport. ### Method Signature ```go func (tp *LocalTransport) GetProtocol() string ``` ``` -------------------------------- ### Get Network from NetMsg Source: https://pkg.go.dev/stdchat.org Retrieves the network information from a NetMsg. ```go func (msg NetMsg) GetNetwork() EntityInfo ``` -------------------------------- ### Get Service State Information Source: https://pkg.go.dev/stdchat.org/service Retrieves the current state information for the service, including protocol, networks, and subscriptions. ```go func (svc *Service) GetStateInfo() ServiceStateInfo ``` -------------------------------- ### HTTP Handler for Expvar Source: https://pkg.go.dev/expvar Returns the expvar HTTP Handler. This is useful for installing the handler in a non-standard location. ```APIDOC ## Handler ### Description Returns the expvar HTTP Handler. This is only needed to install the handler in a non-standard location. ### Method GET ### Endpoint /debug/vars ### Response #### Success Response (200) - **Content-Type**: application/json - **Body**: JSON object containing exported variables. ``` -------------------------------- ### Get Source: https://pkg.go.dev/stdchat.org Retrieves the value associated with a specified key. Returns an empty string if the key is not found. ```APIDOC ## func (ValuesInfo) Get ¶ ``` func (vi ValuesInfo) Get(key string) string ``` Get the value of the specified key, or empty string. ``` -------------------------------- ### Get Service Transporter Source: https://pkg.go.dev/stdchat.org/service Returns the Transporter instance used by the service. ```go func (svc *Service) Transporter() Transporter ``` -------------------------------- ### Get Message by Type Source: https://pkg.go.dev/stdchat.org Retrieves a specific Message from MessageInfo by its type. Returns an empty message if not found. ```go func (msg MessageInfo) Get(msgType string) Message ``` -------------------------------- ### NewClient Function Source: https://pkg.go.dev/stdchat.org/service/dummy Creates a new client for the dummy service. Requires a service instance, network address, user credentials, and value information. ```go func NewClient(svc *service.Service, addr, nick, pass string, values stdchat.ValuesInfo) (service.Networker, error) ``` -------------------------------- ### Initialize MediaInfo Source: https://pkg.go.dev/stdchat.org Initializes a MediaInfo object with a type and URL. ```go func (x *MediaInfo) Init(typ, url string) ``` -------------------------------- ### NewService Source: https://pkg.go.dev/stdchat.org/service/dummy Initializes a new service instance. ```APIDOC ## func NewService ### Description Initializes a new service instance. ### Signature ```go func NewService(tp service.Transporter) *service.Service ``` ``` -------------------------------- ### NewClient Source: https://pkg.go.dev/stdchat.org/service/dummy Creates a new client instance for the dummy service. ```APIDOC ## func NewClient ### Description Creates a new client instance for the dummy service. ### Signature ```go func NewClient(svc *service.Service, addr, nick, pass string, values stdchat.ValuesInfo) (service.Networker, error) ``` ``` -------------------------------- ### Define Networker Interface Source: https://pkg.go.dev/stdchat.org/service Defines the Networker interface for a client implementation of a network. It includes methods for closing connections, logging out, starting, and retrieving network/connection IDs. ```go type Networker interface { io.Closer Receiver Logout(reason string) error // Same as Close() with logout reason. Start(ctx context.Context, id string) error // id = request id NetworkID() string ConnID() string // empty if no connections. Context() context.Context Closed() bool GetStateInfo() ClientStateInfo } ``` -------------------------------- ### Initialize NetMsg Source: https://pkg.go.dev/stdchat.org Initializes a NetMsg with provided IDs and protocol information. ```go func (msg *NetMsg) Init(id, typ, protocol, networkID string) ``` -------------------------------- ### NewService Function Source: https://pkg.go.dev/stdchat.org/service/dummy Initializes a new service instance with a given transporter. ```go func NewService(tp service.Transporter) *service.Service ``` -------------------------------- ### WebServer ServeURL Method Source: https://pkg.go.dev/stdchat.org/service Serves content at a given URL path. It takes a network, a path suffix, and an http.Handler, returning the full URL and an error if any. This method is part of the Transporter interface. ```go func (ws *WebServer) ServeURL(network, pathSuffix string, handler http.Handler) (string, error) ``` -------------------------------- ### Initialize EntityInfo Source: https://pkg.go.dev/stdchat.org Initializes an EntityInfo with a given ID and type. ```go func (x *EntityInfo) Init(id, typ string) ``` -------------------------------- ### Get ID from IDInfo Source: https://pkg.go.dev/stdchat.org Retrieves the unique identifier from an IDInfo. ```go func (x IDInfo) GetID() string ``` -------------------------------- ### WebServer ServeHTTP Method Source: https://pkg.go.dev/stdchat.org/service Handles incoming HTTP requests for the WebServer. This method implements the http.Handler interface. ```go func (ws *WebServer) ServeHTTP(w http.ResponseWriter, r *http.Request) ``` -------------------------------- ### Options Struct Definition Source: https://pkg.go.dev/stdchat.org/provider Options defines the configuration parameters for serving a provider, including address, authentication, connection limits, and TLS settings. ```go type Options struct { Addr string Password string MaxConns int AutoPassword bool AutoExit bool // TLS: CertPath, PrivateKeyPath string } ``` -------------------------------- ### Client Context Method Source: https://pkg.go.dev/stdchat.org/service/dummy Returns the context associated with the client. ```go func (client *Client) Context() context.Context ``` -------------------------------- ### Create New Service Source: https://pkg.go.dev/stdchat.org/service Creates a new Service instance. Requires a Transporter and a NewClientFunc. A lock is acquired during client creation. ```go func NewService(tp Transporter, newClient NewClientFunc) *Service ``` -------------------------------- ### Serve Function Signature Source: https://pkg.go.dev/stdchat.org/provider Serve handles requests on a provided listener with specified options and service. It does not handle TLS. ```go func Serve(ln net.Listener, opts Options, svc service.Servicer, tp service.MultiTransporter) error ``` -------------------------------- ### WebServer.ServeHTTP Source: https://pkg.go.dev/stdchat.org/service Handles incoming HTTP requests. ```APIDOC ## WebServer.ServeHTTP ### Description Handles incoming HTTP requests. ### Method Signature ```go func (ws *WebServer) ServeHTTP(w http.ResponseWriter, r *http.Request) ``` ### Parameters * `w` (http.ResponseWriter) - The response writer. * `r` (*http.Request) - The incoming HTTP request. ``` -------------------------------- ### Client GetStateInfo Method Source: https://pkg.go.dev/stdchat.org/service/dummy Retrieves the current state information of the client. ```go func (client *Client) GetStateInfo() service.ClientStateInfo ``` -------------------------------- ### Get LocalTransport Protocol Source: https://pkg.go.dev/stdchat.org/service Retrieves the protocol string associated with the LocalTransport. ```go func (tp *LocalTransport) GetProtocol() string ``` -------------------------------- ### Create and use an Int variable Source: https://pkg.go.dev/expvar Create a new 64-bit integer variable using NewInt. You can then atomically add to or set its value. ```go func NewInt(name string) *Int ``` ```go func (v *Int) Add(delta int64) ``` ```go func (v *Int) Set(value int64) ``` -------------------------------- ### Get Protocol from MultiTransport Source: https://pkg.go.dev/stdchat.org/service Retrieves the protocol string from the MultiTransport. This method is part of the Transporter interface. ```go func (tp *MultiTransport) GetProtocol() string ``` -------------------------------- ### Client Handler Method Source: https://pkg.go.dev/stdchat.org/service/dummy Handles general chat messages for the client. ```go func (client *Client) Handler(msg *stdchat.ChatMsg) ``` -------------------------------- ### Get Source: https://pkg.go.dev/expvar Retrieves a named exported variable from the global registry. Returns nil if the name has not been registered. ```APIDOC ## func Get ### Description Retrieves a named exported variable. It returns nil if the name has not been registered. ### Signature ```go func Get(name string) Var ``` ``` -------------------------------- ### Define Client State Information Source: https://pkg.go.dev/stdchat.org/service Defines the structure for client state, including network and subscription information. ```go type ClientStateInfo struct { Network stdchat.NetworkStateInfo Subscriptions []stdchat.SubscriptionStateInfo } ``` -------------------------------- ### Map.Init Source: https://pkg.go.dev/expvar Initializes the map, removing all existing keys. Returns the map itself for chaining. ```APIDOC ## func (*Map) Init ### Description Removes all keys from the map. ### Signature ```go func (v *Map) Init() *Map ``` ``` -------------------------------- ### Dummy Protocol Constant Source: https://pkg.go.dev/stdchat.org/service/dummy Defines the protocol string used by the dummy package. ```go const Protocol = "dummy" ``` -------------------------------- ### Serve Source: https://pkg.go.dev/stdchat.org/provider Serves a service provider on a given network listener with specified options. ```APIDOC ## Serve ### Description Serves a service provider on a given network listener with specified options. Does not consider TLS (cert & privkey ignored). ### Signature ```go func Serve(ln net.Listener, opts Options, svc service.Servicer, tp service.MultiTransporter) error ``` ### Parameters - **ln** (net.Listener) - The network listener to serve on. - **opts** (Options) - Configuration options for the provider. - **svc** (service.Servicer) - The service implementation to serve. - **tp** (service.MultiTransporter) - The transport layer for the service. ``` -------------------------------- ### Get Name from IDInfo Source: https://pkg.go.dev/stdchat.org Retrieves the name for an IDInfo. Falls back to the ID field if Name is empty. ```go func (x IDInfo) GetName() string ``` -------------------------------- ### Get All Networker Clients Source: https://pkg.go.dev/stdchat.org/service Returns a slice containing all currently active Networker clients managed by the service. ```go func (svc *Service) GetClients() []Networker ``` -------------------------------- ### Run Function Signature Source: https://pkg.go.dev/stdchat.org/provider Run is a convenience function to execute an entire provider program with a given protocol and service constructor. ```go func Run(protocol string, newService func(t service.Transporter) service.Servicer) error ``` -------------------------------- ### Get Networker Client by Network ID Source: https://pkg.go.dev/stdchat.org/service Retrieves a specific Networker client using its network ID. ```go func (svc *Service) GetClientByNetwork(networkID string) Networker ``` -------------------------------- ### Client Type Definition Source: https://pkg.go.dev/stdchat.org/service/dummy Represents a client connection within the dummy service. Contains internal fields. ```go type Client struct { // contains filtered or unexported fields } ``` -------------------------------- ### Options Source: https://pkg.go.dev/stdchat.org/provider Represents the configuration options for serving a provider. ```APIDOC ## Options ### Description Options for serving this provider. ### Fields - **Addr** (string) - The network address to bind to. - **Password** (string) - The password for authentication. - **MaxConns** (int) - The maximum number of concurrent connections. - **AutoPassword** (bool) - Whether to automatically handle password authentication. - **AutoExit** (bool) - Whether to automatically exit after serving. - **CertPath** (string) - Path to the TLS certificate file. - **PrivateKeyPath** (string) - Path to the TLS private key file. ``` -------------------------------- ### Client UserName Method Source: https://pkg.go.dev/stdchat.org/service/dummy Returns the username of the client. ```go func (client *Client) UserName() string ``` -------------------------------- ### MessageInfo Source: https://pkg.go.dev/stdchat.org Represents a message in various types and formats. Provides methods to get, set, and retrieve message content. ```APIDOC #### type MessageInfo ¶ ``` type MessageInfo []Message ``` MessageInfo represents a message in various types/formats. ``` ```APIDOC #### func (MessageInfo) Get ¶ ``` func (msg MessageInfo) Get(msgType string) Message ``` Get message in the specified type, or an empty message. ``` ```APIDOC #### func (*MessageInfo) Set ¶ ``` func (msg *MessageInfo) Set(msgType, content string) ``` ``` ```APIDOC #### func (*MessageInfo) SetText ¶ ``` func (msg *MessageInfo) SetText(content string) ``` SetText in text/plain type. ``` ```APIDOC #### func (MessageInfo) String ¶ ``` func (msg MessageInfo) String() string ``` String returns the content for text/plain, or empty string. ``` -------------------------------- ### Service.Login Source: https://pkg.go.dev/stdchat.org/service Logs in a client to the service. ```APIDOC ## Service.Login ### Description Logs in a client to the service. ### Method Signature ```go func (svc *Service) Login(remote, userID, auth string, values stdchat.ValuesInfo, id string) (Networker, error) ``` ### Parameters * `remote` (string) - The remote address of the client. * `userID` (string) - The user ID for login. * `auth` (string) - The authentication token or credentials. * `values` (stdchat.ValuesInfo) - Additional values for the login request. * `id` (string) - An identifier for the login request. ``` -------------------------------- ### Get an exported variable Source: https://pkg.go.dev/expvar Retrieves a named exported variable from the expvar registry. Returns nil if the variable is not found. ```go func Get(name string) Var ``` -------------------------------- ### Run Source: https://pkg.go.dev/stdchat.org/provider A convenience function to run an entire provider program with a specified protocol and service constructor. ```APIDOC ## Run ### Description A convenience function to run an entire provider program with a specified protocol and service constructor. ### Signature ```go func Run(protocol string, newService func(t service.Transporter) service.Servicer) error ``` ### Parameters - **protocol** (string) - The network protocol to use (e.g., "tcp", "ws"). - **newService** (func(t service.Transporter) service.Servicer) - A function that creates a new service instance with the given transporter. ``` -------------------------------- ### Get Display Name from IDInfo Source: https://pkg.go.dev/stdchat.org Retrieves the display name for an IDInfo. Falls back to the Name field if DisplayName is empty. ```go func (x IDInfo) GetDisplayName() string ``` -------------------------------- ### Client NetworkName Method Source: https://pkg.go.dev/stdchat.org/service/dummy Returns the name of the network the client is connected to. ```go func (client *Client) NetworkName() string ``` -------------------------------- ### DecodeMsg Source: https://pkg.go.dev/stdchat.org Decodes raw message bytes into a Go interface. The returned error can be unwrapped to get the underlying JSON unmarshalling error. ```APIDOC ## DecodeMsg ### Description DecodeMsg decodes rawMsg bytes into v. Error returned will be of type DecodeMsgError, use Unwrap to get the error from the JSON unmarshaller. ### Signature ```go func DecodeMsg(rawMsg []byte, v interface{}) error ``` ``` -------------------------------- ### Client CmdHandler Method Source: https://pkg.go.dev/stdchat.org/service/dummy Handles incoming command messages for the client. ```go func (client *Client) CmdHandler(msg *stdchat.CmdMsg) ``` -------------------------------- ### Statuser interface definition Source: https://pkg.go.dev/stdchat.org Defines the Statuser interface for objects that have status information, requiring methods to get type, protocol, and a string representation. ```go type Statuser interface { GetType() string GetProtocol() string String() string } ``` -------------------------------- ### Command Message Creation Helpers Source: https://pkg.go.dev/stdchat.org Provides factory functions for creating different types of command messages, including general commands, login requests, logout requests (with and without reason), and raw commands. ```go func NewCmd(id, command string, args ...string) *CmdMsg ``` ```go func NewLogin(id, remote, userID, auth string) *CmdMsg ``` ```go func NewLogout(id, logoutID string) *CmdMsg ``` ```go func NewLogoutReason(id, logoutID, reason string) *CmdMsg ``` ```go func NewRaw(id, netID string, args ...string) *CmdMsg ``` -------------------------------- ### Get the unquoted value of a String variable Source: https://pkg.go.dev/expvar Retrieves the unquoted string value stored in the String variable. This is useful when the JSON representation is not needed. ```go func (v *String) Value() string ``` -------------------------------- ### Get a variable from a Map Source: https://pkg.go.dev/expvar Retrieves a variable from the Map using its key. Returns the Var interface if found, otherwise behavior is undefined (likely nil). ```go func (v *Map) Get(key string) Var ``` -------------------------------- ### String representation of a String variable Source: https://pkg.go.dev/expvar Returns a string representation of the String variable, which must be a valid JSON value. To get the unquoted string, use the Value method. ```go func (v *String) String() string ``` -------------------------------- ### Marshal JSON for MediaInfo Source: https://pkg.go.dev/stdchat.org Custom JSON marshaling for MediaInfo. ```go func (x *MediaInfo) MarshalJSON() ([]byte, error) ``` -------------------------------- ### Default Options for Provider Source: https://pkg.go.dev/stdchat.org/provider DefaultOptions provides a default configuration for the provider. It is recommended to create a copy before modification or calling AddFlags. ```go var DefaultOptions = Options{ MaxConns: 1, AutoExit: true, } ``` -------------------------------- ### Get a single value by key in Go Source: https://pkg.go.dev/stdchat.org Retrieves the value associated with a given key. Returns an empty string if the key is not found. Suitable for accessing a unique value for a key. ```go func (vi ValuesInfo) Get(key string) string ``` -------------------------------- ### Define UserInfo structure Source: https://pkg.go.dev/stdchat.org Defines user information, including the user entity, photo, and associated values. ```go type UserInfo struct { User EntityInfo `json:"user"` // user Photo MediaInfo `json:"photo,omitempty"` // URL or no photo. Values ValuesInfo `json:"values,omitempty"` // user values. } ``` -------------------------------- ### Transporter Interface Definition Source: https://pkg.go.dev/stdchat.org/service Defines the interface for a chat service transport. It includes methods for closing, getting the protocol, advertising the service, publishing messages and errors, and serving/stopping URL content. ```go type Transporter interface { io.Closer GetProtocol() string // Advertise the service is up, // this needs to be called before clients can do anything. Advertise() error // Publish a message. // network and chat can be empty. // node is the final part in the topic name, as in chat/Protocol/node // e.g. to publish a protocol msg, use Publish("", "", "my-info", payload) Publish(network, chat, node string, payload interface{}) error // id should be the ID of the request (if a request), which can be empty. // network can be empty if a protocol msg. PublishError(id string, network string, err error) error // Full URL returned. // pathSuffix is the last part of the URL path, such as userA/foo4.png // handler is set to a HTTP client handler to serve the headers+content. // It is resonable that a directory is served. // Use StopServeURL to stop serving. ServeURL(network, pathSuffix string, handler http.Handler) (string, error) // Cancel serving a URL. // If this is the last served URL, the web service may shut down. StopServeURL(network, pathSuffix string) } ``` -------------------------------- ### Initialize or clear a Map Source: https://pkg.go.dev/expvar Removes all keys from the Map, effectively resetting it. Use this to clear all stored variables. ```go func (v *Map) Init() *Map ``` -------------------------------- ### ConnMsg Initialization Source: https://pkg.go.dev/stdchat.org Provides a method to initialize a ConnMsg with all necessary details, including message ID, type, protocol, network ID, connection ID, and the connection state. ```go func (*ConnMsg) Init(id, typ, protocol, netID string, connID string, state ConnState) ``` -------------------------------- ### Login User to Network Source: https://pkg.go.dev/stdchat.org/service Logs in a user to a specified network, returning a Networker client or an error. ```go func (svc *Service) Login(remote, userID, auth string, values stdchat.ValuesInfo, id string) (Networker, error) ``` -------------------------------- ### Create and use a String variable Source: https://pkg.go.dev/expvar Create a new string variable using NewString. You can set its value. ```go func NewString(name string) *String ``` ```go func (v *String) Set(value string) ``` -------------------------------- ### Protocol Constant Source: https://pkg.go.dev/stdchat.org/service/dummy Defines the protocol string for the dummy package. ```APIDOC ## Constants ### Protocol ```go const Protocol = "dummy" ``` ``` -------------------------------- ### Define SubscriptionStateInfo structure Source: https://pkg.go.dev/stdchat.org Defines subscription state information, including network, protocol, destination, subject, members, values, and history URL. ```go type SubscriptionStateInfo struct { TypeInfo // subscription-state Network EntityInfo `json:"net"` Protocol string `json:"proto"` Destination EntityInfo `json:"dest"` Subject MessageInfo `json:"subject,omitempty"` Members []MemberInfo `json:"members,omitempty"` Values ValuesInfo `json:"values,omitempty"` HistoryURL string `json:"history,omitempty"` // empty if not supported. } ``` -------------------------------- ### Create and use a Float variable Source: https://pkg.go.dev/expvar Create a new 64-bit float variable using NewFloat. You can then atomically add to or set its value. ```go func NewFloat(name string) *Float ``` ```go func (v *Float) Add(delta float64) ``` ```go func (v *Float) Set(value float64) ``` -------------------------------- ### Create a new String variable Source: https://pkg.go.dev/expvar Creates and returns a pointer to a new String variable with the given name. This variable can be registered and updated. ```go func NewString(name string) *String ``` -------------------------------- ### ProtocolStateInfo.String Source: https://pkg.go.dev/stdchat.org Returns a string representation of ProtocolStateInfo. ```APIDOC ## ProtocolStateInfo.String ### Description String returns a string representation of the ProtocolStateInfo. ### Method func (x ProtocolStateInfo) String() string ``` -------------------------------- ### GetProtocol method for SubscriptionStateInfo Source: https://pkg.go.dev/stdchat.org Method to retrieve the protocol string from SubscriptionStateInfo. ```go func (x SubscriptionStateInfo) GetProtocol() string ``` -------------------------------- ### Add method for ValuesInfo Source: https://pkg.go.dev/stdchat.org Adds a key-value pair to the ValuesInfo, regardless of whether the key already exists. ```go func (vi *ValuesInfo) Add(key, value string) *ValuesInfo ``` -------------------------------- ### NetworkStateInfo.String Source: https://pkg.go.dev/stdchat.org Returns a string representation of NetworkStateInfo. ```APIDOC ## NetworkStateInfo.String ### Description String returns a string representation of the NetworkStateInfo. ### Method func (x NetworkStateInfo) String() string ``` -------------------------------- ### String type methods Source: https://pkg.go.dev/expvar Provides String and Value methods for the String type, satisfying the Var interface. ```go func (v *String) String() string ``` ```go func (v *String) Value() string ``` -------------------------------- ### Service.Protocol Source: https://pkg.go.dev/stdchat.org/service Returns the protocol string of the service. ```APIDOC ## Service.Protocol ### Description Returns the protocol string of the service. ### Method Signature ```go func (svc *Service) Protocol() string ``` ``` -------------------------------- ### WebServer.ServeURL Source: https://pkg.go.dev/stdchat.org/service Serves HTTP requests for a given network and path suffix. ```APIDOC ## WebServer.ServeURL ### Description Serves HTTP requests for a given network and path suffix. ### Method Signature ```go func (ws *WebServer) ServeURL(network, pathSuffix string, handler http.Handler) (string, error) ``` ### Parameters * `network` (string) - The network identifier. * `pathSuffix` (string) - The suffix for the URL path. * `handler` (http.Handler) - The HTTP handler to serve. ``` -------------------------------- ### GetProtocol method for NetworkStateInfo Source: https://pkg.go.dev/stdchat.org Method to retrieve the protocol string from NetworkStateInfo. ```go func (x NetworkStateInfo) GetProtocol() string ``` -------------------------------- ### Service.GetClients Source: https://pkg.go.dev/stdchat.org/service Returns a list of all connected clients. ```APIDOC ## Service.GetClients ### Description Returns a list of all connected clients. ### Method Signature ```go func (svc *Service) GetClients() []Networker ``` ``` -------------------------------- ### ConnState Source: https://pkg.go.dev/stdchat.org Represents the connection state. ```APIDOC ## type ConnState ### Description ConnState represents the connection state. Note that ConnectFailed during Connecting or Reconnecting does not indicate the end of the connection attempt, a Disconnected does. ConnectFailed goes to the conn topic, not error; it is a ConnMsg and is not an exceptional error. ### Constants - **Connecting** (ConnState) = "connecting" - **Connected** (ConnState) = "connected" - **Reconnecting** (ConnState) = "reconnecting" - **Disconnected** (ConnState) = "disconnected" - **ConnectFailed** (ConnState) = "failed" ``` -------------------------------- ### Set Message by Type Source: https://pkg.go.dev/stdchat.org Sets a Message in MessageInfo for a given type. ```go func (msg *MessageInfo) Set(msgType, content string) ``` -------------------------------- ### Int type methods Source: https://pkg.go.dev/expvar Provides String and Value methods for the Int type, satisfying the Var interface. ```go func (v *Int) String() string ``` ```go func (v *Int) Value() int64 ``` -------------------------------- ### Register a new variable with expvar Source: https://pkg.go.dev/expvar Use Publish to declare a named exported variable. This is typically done in a package's init function. Panics if the name is already registered. ```go func Publish(name string, v Var) ``` -------------------------------- ### Client Methods Source: https://pkg.go.dev/stdchat.org/service/dummy Methods available on the Client type. ```APIDOC ## type Client ### Methods #### Close ##### Description Closes the client connection. ##### Signature ```go func (client *Client) Close() error ``` #### Closed ##### Description Checks if the client is closed. ##### Signature ```go func (client *Client) Closed() bool ``` #### CmdHandler ##### Description Handles command messages. ##### Signature ```go func (client *Client) CmdHandler(msg *stdchat.CmdMsg) ``` #### ConnID ##### Description Returns the connection ID. ##### Signature ```go func (client *Client) ConnID() string ``` #### Context ##### Description Returns the client's context. ##### Signature ```go func (client *Client) Context() context.Context ``` #### GetStateInfo ##### Description Retrieves the client's state information. ##### Signature ```go func (client *Client) GetStateInfo() service.ClientStateInfo ``` #### Handler ##### Description Handles chat messages. ##### Signature ```go func (client *Client) Handler(msg *stdchat.ChatMsg) ``` #### Logout ##### Description Logs out the client with a specified reason. ##### Signature ```go func (client *Client) Logout(reason string) error ``` #### NetworkID ##### Description Returns the network ID. ##### Signature ```go func (client *Client) NetworkID() string ``` #### NetworkName ##### Description Returns the network name. ##### Signature ```go func (client *Client) NetworkName() string ``` #### Start ##### Description Starts the client with a given context and ID. ##### Signature ```go func (client *Client) Start(ctx context.Context, id string) error ``` #### UserID ##### Description Returns the user ID. ##### Signature ```go func (client *Client) UserID() string ``` #### UserName ##### Description Returns the user name. ##### Signature ```go func (client *Client) UserName() string ``` ``` -------------------------------- ### Service.Context Source: https://pkg.go.dev/stdchat.org/service Returns the context associated with the service. ```APIDOC ## Service.Context ### Description Returns the context associated with the service. ### Method Signature ```go func (svc *Service) Context() context.Context ``` ``` -------------------------------- ### Default expvar variables Source: https://pkg.go.dev/expvar The expvar package automatically registers cmdline (os.Args) and memstats (runtime.Memstats) variables when imported. ```text cmdline os.Args memstats runtime.Memstats ``` -------------------------------- ### WebServer Struct Definition Source: https://pkg.go.dev/stdchat.org/service Represents a web server with configuration for its public URL and bind address. It is used for serving web content. ```go type WebServer struct { PublicURL string // uses localhost and a random port if empty. BindAddr string // parses from PublicURL if empty. // contains filtered or unexported fields } ``` -------------------------------- ### Define MediaInfo struct Source: https://pkg.go.dev/stdchat.org Contains information about media content, including type, name, URLs, expiration, and values. It embeds TypeInfo. ```go type MediaInfo struct { TypeInfo // MIME type, or hint such as "image/*" Name string `json:"name,omitempty"` // Default is file name from URL. URL string `json:"url"` ThumbURL string `json:"thumb,omitempty"` // optional thumbnail. Expires time.Time `json:"expires,omitempty"` // When the URL expires. Values ValuesInfo `json:"values,omitempty"` } ``` -------------------------------- ### ChatMsg Methods Source: https://pkg.go.dev/stdchat.org Provides methods to retrieve the ChatMsg itself and initialize it with network-specific details. IsMsg indicates if it's a valid message. ```go func (*ChatMsg) GetChatMsg() *ChatMsg ``` ```go func (*ChatMsg) Init(id, typ, protocol, networkID string) ``` ```go func (*ChatMsg) IsMsg() bool ``` -------------------------------- ### Define NetworkStateInfo structure Source: https://pkg.go.dev/stdchat.org Defines the structure for network state information, including network, protocol, connection, self, and readiness. ```go type NetworkStateInfo struct { TypeInfo // network-state Network EntityInfo `json:"net"` Protocol string `json:"proto"` Connection EntityInfo `json:"conn,omitempty"` // Optional, if connections. Myself EntityInfo `json:"myself"` Values ValuesInfo `json:"values,omitempty"` Ready bool `json:"ready"` } ``` -------------------------------- ### WebServer FindHandler Method Source: https://pkg.go.dev/stdchat.org/service Finds an HTTP handler for a given path within the WebServer. Returns nil if no handler is found. ```go func (ws *WebServer) FindHandler(path string) http.Handler ``` -------------------------------- ### Client Close Method Source: https://pkg.go.dev/stdchat.org/service/dummy Closes the client connection. Returns an error if the closure fails. ```go func (client *Client) Close() error ``` -------------------------------- ### GetProtocol method for ProtocolStateInfo Source: https://pkg.go.dev/stdchat.org Method to retrieve the protocol string from ProtocolStateInfo. ```go func (x ProtocolStateInfo) GetProtocol() string ``` -------------------------------- ### NetworkStateInfo.GetProtocol Source: https://pkg.go.dev/stdchat.org Retrieves the protocol string from NetworkStateInfo. ```APIDOC ## NetworkStateInfo.GetProtocol ### Description GetProtocol retrieves the protocol string from the NetworkStateInfo. ### Method func (x NetworkStateInfo) GetProtocol() string ``` -------------------------------- ### Options.AddFlags Source: https://pkg.go.dev/stdchat.org/provider Adds command-line flags for the Options struct to a flag.FlagSet. ```APIDOC ## (*Options) AddFlags ### Description Adds flags for the options to the given flag.FlagSet. ### Signature ```go func (opts *Options) AddFlags(flags *flag.FlagSet) ``` ### Parameters - **flags** (*flag.FlagSet) - The flag set to which the flags will be added. ``` -------------------------------- ### Client Logout Method Source: https://pkg.go.dev/stdchat.org/service/dummy Logs the client out of the service, providing a reason for disconnection. ```go func (client *Client) Logout(reason string) error ``` -------------------------------- ### Service.CmdHandler Source: https://pkg.go.dev/stdchat.org/service Handles incoming command messages. ```APIDOC ## Service.CmdHandler ### Description Handles incoming command messages. ### Method Signature ```go func (svc *Service) CmdHandler(msg *stdchat.CmdMsg) ``` ### Parameters * `msg` (*stdchat.CmdMsg) - The command message to handle. ``` -------------------------------- ### String representation of MessageInfo Source: https://pkg.go.dev/stdchat.org Returns the content of the 'text/plain' message, or an empty string if not present. ```go func (msg MessageInfo) String() string ``` -------------------------------- ### Import expvar for side effects Source: https://pkg.go.dev/expvar Import the expvar package using the blank identifier to register its HTTP handler and default variables without directly using its API. ```go import _ "expvar" ``` -------------------------------- ### ProtocolStateInfo.GetProtocol Source: https://pkg.go.dev/stdchat.org Retrieves the protocol string from ProtocolStateInfo. ```APIDOC ## ProtocolStateInfo.GetProtocol ### Description GetProtocol retrieves the protocol string from the ProtocolStateInfo. ### Method func (x ProtocolStateInfo) GetProtocol() string ``` -------------------------------- ### Set Text Content for Message Source: https://pkg.go.dev/stdchat.org Sets the text content for a Message object. ```go func (msg *Message) SetText(content string) ``` -------------------------------- ### Define ProtocolStateInfo structure Source: https://pkg.go.dev/stdchat.org Defines the structure for protocol state information, including protocol and values. ```go type ProtocolStateInfo struct { TypeInfo // proto-state Protocol string `json:"proto"` Values ValuesInfo `json:"values,omitempty"` } ``` -------------------------------- ### Create and use a Map variable Source: https://pkg.go.dev/expvar Create a new map variable using NewMap. You can add integer or float values to specific keys, or set any Var type. ```go func NewMap(name string) *Map ``` ```go func (v *Map) Add(key string, delta int64) ``` ```go func (v *Map) AddFloat(key string, delta float64) ``` ```go func (v *Map) Set(key string, av Var) ``` -------------------------------- ### SubscriptionStateInfo.GetProtocol Source: https://pkg.go.dev/stdchat.org Retrieves the protocol string from SubscriptionStateInfo. ```APIDOC ## SubscriptionStateInfo.GetProtocol ### Description GetProtocol retrieves the protocol string from the SubscriptionStateInfo. ### Method func (x SubscriptionStateInfo) GetProtocol() string ``` -------------------------------- ### Service.Handler Source: https://pkg.go.dev/stdchat.org/service Handles incoming chat messages. ```APIDOC ## Service.Handler ### Description Handles incoming chat messages. ### Method Signature ```go func (svc *Service) Handler(msg *stdchat.ChatMsg) ``` ### Parameters * `msg` (*stdchat.ChatMsg) - The chat message to handle. ``` -------------------------------- ### AddFlags Method Signature Source: https://pkg.go.dev/stdchat.org/provider AddFlags adds command-line flags for the Options configuration to a flag.FlagSet. ```go func (opts *Options) AddFlags(flags *flag.FlagSet) ``` -------------------------------- ### Float type methods Source: https://pkg.go.dev/expvar Provides String and Value methods for the Float type, satisfying the Var interface. ```go func (v *Float) String() string ``` ```go func (v *Float) Value() float64 ``` -------------------------------- ### MarshalJSON method for StateEntry Source: https://pkg.go.dev/stdchat.org Method to marshal StateEntry into JSON format. ```go func (se StateEntry) MarshalJSON() ([]byte, error) ``` -------------------------------- ### GetAll values for a key in Go Source: https://pkg.go.dev/stdchat.org Retrieves all values associated with a specified key. Returns nil if no values are found for the key. Use this when a key can have multiple associated values. ```go func (vi ValuesInfo) GetAll(key string) []string ``` -------------------------------- ### Define Service Structure Source: https://pkg.go.dev/stdchat.org/service Defines the Service struct, representing a chat service with an option for verbose logging. ```go type Service struct { Verbose bool // verbose output to log.Print/Printf // contains filtered or unexported fields } ``` -------------------------------- ### Set Text Message Source: https://pkg.go.dev/stdchat.org Sets the text content for a MessageInfo, specifically for the 'text/plain' type. ```go func (msg *MessageInfo) SetText(content string) ``` -------------------------------- ### GetAll Source: https://pkg.go.dev/stdchat.org Retrieves all values associated with a specified key. Returns nil if no values are found for the key. ```APIDOC ## func (ValuesInfo) GetAll ¶ ``` func (vi ValuesInfo) GetAll(key string) []string ``` GetAll returns all the values for the specified key, or nil if none. ``` -------------------------------- ### NewLogin Source: https://pkg.go.dev/stdchat.org Helper function to create a login request message. ```APIDOC ## func NewLogin ### Description NewLogin is a login request. ### Signature ```go func NewLogin(id, remote, userID, auth string) *CmdMsg ``` ``` -------------------------------- ### Define ServiceStateInfo Structure Source: https://pkg.go.dev/stdchat.org/service Defines the ServiceStateInfo struct, containing state information for the service's protocol, networks, and subscriptions. ```go type ServiceStateInfo struct { Protocol stdchat.ProtocolStateInfo Networks []stdchat.NetworkStateInfo Subscriptions []stdchat.SubscriptionStateInfo } ``` -------------------------------- ### NewCmd Source: https://pkg.go.dev/stdchat.org Helper function to create a command message. ```APIDOC ## func NewCmd ### Description NewCmd is a helper to create a command. ### Signature ```go func NewCmd(id, command string, args ...string) *CmdMsg ``` ``` -------------------------------- ### ListenAndServeWS Source: https://pkg.go.dev/stdchat.org/provider Listens and serves a websocket connection for the service provider. ```APIDOC ## ListenAndServeWS ### Description Listens and serves a websocket connection for the service provider. ### Signature ```go func ListenAndServeWS(opts Options, svc service.Servicer, tp service.MultiTransporter) error ``` ### Parameters - **opts** (Options) - Configuration options for the provider. - **svc** (service.Servicer) - The service implementation to serve. - **tp** (service.MultiTransporter) - The transport layer for the service. ``` -------------------------------- ### Set Name for IDInfo Source: https://pkg.go.dev/stdchat.org Sets the Name and DisplayName for an IDInfo. Ensure the ID is set before calling this method. ```go func (x *IDInfo) SetName(name, displayName string) ``` -------------------------------- ### Check Command Arguments Source: https://pkg.go.dev/stdchat.org/service Ensures a CmdMsg has at least n arguments. Returns true if sufficient, otherwise false and publishes an error. ```go func (svc *Service) CheckArgs(n int, msg *stdchat.CmdMsg) bool ``` -------------------------------- ### WebServer.FindHandler Source: https://pkg.go.dev/stdchat.org/service Finds an HTTP handler for a given path. ```APIDOC ## WebServer.FindHandler ### Description Finds an HTTP handler for a given path. ### Method Signature ```go func (ws *WebServer) FindHandler(path string) http.Handler ``` ### Parameters * `path` (string) - The path to find the handler for. ``` -------------------------------- ### Func Type Source: https://pkg.go.dev/expvar Implements Var by calling a function and formatting its return value. ```APIDOC ## Func ### Description Func implements Var by calling the function and formatting the returned value using JSON. ### Value ```go func (f Func) Value() any ``` Returns the result of calling the function. ``` -------------------------------- ### SubscriptionStateInfo.String Source: https://pkg.go.dev/stdchat.org Returns a string representation of SubscriptionStateInfo. ```APIDOC ## SubscriptionStateInfo.String ### Description String returns a string representation of the SubscriptionStateInfo. ### Method func (x SubscriptionStateInfo) String() string ``` -------------------------------- ### Define NewClientFunc Type Source: https://pkg.go.dev/stdchat.org/service Defines the NewClientFunc type, a function signature for creating new Networker clients. ```go type NewClientFunc = func(svc *Service, remote, userID, auth string, values stdchat.ValuesInfo) (Networker, error) ``` -------------------------------- ### WebServer Close Method Source: https://pkg.go.dev/stdchat.org/service Closes the WebServer, releasing any resources it holds. This method implements the io.Closer interface. ```go func (ws *WebServer) Close() error ``` -------------------------------- ### WebServer Struct Source: https://pkg.go.dev/stdchat.org/service The WebServer struct provides functionality for serving HTTP requests and managing served URLs. ```APIDOC ## WebServer Struct ### Description Represents a web server capable of handling HTTP requests and serving content via URLs. ### Fields - `PublicURL` (string): The public URL of the web server. If empty, `localhost` and a random port are used. - `BindAddr` (string): The address to bind to. Parsed from `PublicURL` if empty. ### Methods - `Close() error`: Closes the web server. - `FindHandler(path string) http.Handler`: Finds an HTTP handler for a given path. - `ServeHTTP(w http.ResponseWriter, r *http.Request)`: Handles incoming HTTP requests. - `ServeURL(network, pathSuffix string, handler http.Handler) (string, error)`: Starts serving content at a given URL path suffix for a specific network using the provided HTTP handler. Returns the full URL and an error if any. - `StopServeURL(network, pathSuffix string)`: Stops serving content at the specified URL path suffix for the given network. ``` -------------------------------- ### Define ValuesInfo structure Source: https://pkg.go.dev/stdchat.org Represents zero or more auxiliary key-value pairs, used for protocol-specific or implementation-specific data. ```go type ValuesInfo []KeyValueInfo ``` -------------------------------- ### Handle Command Message Source: https://pkg.go.dev/stdchat.org/service Processes incoming command messages for the service. ```go func (svc *Service) CmdHandler(msg *stdchat.CmdMsg) ``` -------------------------------- ### Client NetworkID Method Source: https://pkg.go.dev/stdchat.org/service/dummy Returns the network ID associated with the client. ```go func (client *Client) NetworkID() string ``` -------------------------------- ### CmdMsg Getters Source: https://pkg.go.dev/stdchat.org Includes a method to retrieve the optional network information associated with a command message and a method to confirm it is a message type. ```go func (CmdMsg) GetNetwork() EntityInfo ``` ```go func (CmdMsg) IsMsg() bool ``` -------------------------------- ### NewRaw Source: https://pkg.go.dev/stdchat.org Helper function to create a raw command message. ```APIDOC ## func NewRaw ### Description NewRaw is a helper to create a raw command. ### Signature ```go func NewRaw(id, netID string, args ...string) *CmdMsg ``` ``` -------------------------------- ### NetworkStateInfo Source: https://pkg.go.dev/stdchat.org Represents network state information, including network, protocol, connection, and readiness. ```APIDOC ## NetworkStateInfo ### Description NetworkStateInfo is network state information. ### Fields - **TypeInfo** (TypeInfo) - Embedded field for type information. - **Network** (EntityInfo) - Information about the network. - **Protocol** (string) - The network protocol. - **Connection** (EntityInfo) - Optional information about the connection. - **Myself** (EntityInfo) - Information about the current entity. - **Values** (ValuesInfo) - Optional auxiliary key-value pairs. - **Ready** (bool) - Indicates if the network state is ready. ``` -------------------------------- ### Close Service Source: https://pkg.go.dev/stdchat.org/service Closes the service and releases associated resources. ```go func (svc *Service) Close() error ``` -------------------------------- ### IsType method for TypeInfo Source: https://pkg.go.dev/stdchat.org Checks if the object's type matches the provided part string. ```go func (x TypeInfo) IsType(part string) bool ``` -------------------------------- ### WebServer.Close Source: https://pkg.go.dev/stdchat.org/service Closes the web server. ```APIDOC ## WebServer.Close ### Description Closes the web server. ### Method Signature ```go func (ws *WebServer) Close() error ``` ``` -------------------------------- ### Define IDInfo struct Source: https://pkg.go.dev/stdchat.org Contains identification information for an object, including ID, Name, and DisplayName. Name and DisplayName are optional and fallback to Name and ID respectively if empty. ```go type IDInfo struct { ID string `json:"id"` Name string `json:"name,omitempty"` // use GetName DisplayName string `json:"dispName,omitempty"` // use GetDisplayName } ``` -------------------------------- ### NewString Source: https://pkg.go.dev/expvar Creates and returns a new String variable with the given name. ```APIDOC ## func NewString ### Description Creates and returns a new String variable with the given name. ### Signature ```go func NewString(name string) *String ``` ```