Server

gox.Server provides read-only information on the current instance of gox-server.

gox
name := gox.Server.ProjectName()
address := gox.Server.Address()
uptime := gox.Server.Uptime()

The information belongs to the process that runs the code. It does not represent an added view of the cluster.


Structure

text
Server
{
    ProjectName() string
    InstanceID() string
    StartedAt() time.Time
    Uptime() time.Duration
    Host() string
    Port() int
    Address() string
    IsDevelopment() bool
    IsClustered() bool
}

Methods

MethodDescription
ProjectName()Return the name of the project.
InstanceID()Returns the instance identifier.
StartedAt()Returns the moment the server started.
Uptime()Returns the activity time.
Host()Returns the set host.
Port()Returns the configured port.
Address()Returns the server address.
IsDevelopment()It indicates if the server is in development.
IsClustered()Indicates if there is an active cluster adapter.

ProjectName()

Firma:func (*ServerContext) ProjectName() string

Returns the name of the project charged by the current instance.

gox
projectName := gox.Server.ProjectName()

InstanceID()

Firma:func (*ServerContext) InstanceID() string

Returns the unique identifier of the current instance. Several instances of the same project have different identifiers.

gox
instanceID := gox.Server.InstanceID()

It uses this value for diagnosis and traceability, not as a permanent identity of the project.


StartedAt()

Firma:func (*ServerContext) StartedAt() time.Time

It returns the moment he started the current instance.

gox
startedAt := gox.Server.StartedAt()

The value uses time.Time and can be formatted with Go's normal operations.


Uptime()

Firma:func (*ServerContext) Uptime() time.Duration

Returns the time elapsed from StartedAt().

gox
uptime := gox.Server.Uptime()

The result is calculated when running the method and changes over time.


Host()

Firma:func (*ServerContext) Host() string

Returns the set host to the HTTP server.

gox
host := gox.Server.Host()

Port()

Firma:func (*ServerContext) Port() int

Returns the configured port for the HTTP server.

gox
port := gox.Server.Port()

Address()

Firma:func (*ServerContext) Address() string

Combine Host() and Port() using the Go network address format.

gox
address := gox.Server.Address()

The IPv6 addresses are formed with square brackets where appropriate. If the host is empty or the port is not valid, it returns an empty string.


IsDevelopment()

Firma:func (*ServerContext) IsDevelopment() bool

It indicates whether the instance is executed in development mode.

gox
if gox.Server.IsDevelopment() {
    log.Println("Development mode")
}

IsClustered()

Firma:func (*ServerContext) IsClustered() bool

It indicates whether the instance uses an active distributed adapter.

gox
if gox.Server.IsClustered() {
    log.Println("Cluster enabled")
}

To check the adapter name and manage your errors, use gox.Cluster.

To learn how to set up the distributed adapter, visit Cluster configuration.


Values before the runtime

These APIs depend on the link made by gox-server. If they are consulted before starting the runtime or after closing it, they return their zero values: empty strings, port 0, false, time.Time{} and duration 0.


Integration with Go

The results of the gox.Server use normal Go values and can be directly integrated with records, metrics, health checks and internal logic of the application.

StartedAt() and Uptime() use time.Time and time.Duration, so they keep all the available operations in the standard package time.


Best practices

  • Use InstanceID() for diagnosis, not as a persistent identifier.
  • Use Address() when you need the complete address already standardized.
  • Don't play. IsDevelopment() as a security clearance.
  • See gox.Cluster when you need specific information on the adapter.

See also

Next step

Continue with gox.Storage to maintain temporary status within the current instance.

Storage