package
1.4.15
Repository: https://github.com/mutablelogic/go-server.git
Documentation: pkg.go.dev

# README

nginx

Handler to start, stop, test and reload nginx programatically, assuming you have nginx installed. The following code will start an nginx server, and then stop it after 10 seconds:

package main

import (
    "github.com/mutablelogic/go-server/pkg/handler/nginx"
)

func main() { 
    if nginx, err := nginx.New(nginx.Config{}); err != nil {
        log.Fatal(err)
    }

    // Create a cancellable context
    ctx, cancel := context.WithTimeout(context.Background(),10 * time.Second)
    defer cancel()

    // Run nginx in foreground until timeout is reached
    if err := nginx.Run(ctx); err != nil {
        t.Error(err)
    }
}

Some additional methods can be used to stop, test and reload the server:

type Nginx interface {
    // test the configuration and return an error if it fails
    Test() error

    // test the configuration and then reload it (the SIGHUP signal)
    Reload() error

    // reopen log files (the SIGUSR1 signal)
    Reopen() error

    // return the nginx version string
    Version() string
}

Configuration

The configuration for the nginx server is embedded (no external configuration files are required). By default, a Hello, World static server is setup on port 80. In reality, you'll want to override this configuration with your own.

TODO

API

The commands can be called through an API.

MethodPathScopeDescription
GET/readReturn the nginx version and uptime
PUT/testwriteTest the server configuration
PUT/reloadwriteTest the configuration and then reload it
PUT/reopenwriteReopen log files
GET/configreadRead the current set of configurations
GET/config/{id}readRead a specific configuration file
DELETE/config/{id}writeDelete a configuration, and reload
POST/config/{id}writeCreate a new configuration, then reload
PATCH/config/{id}writeUpdate a configuration enabled or body, and reload on change

The body of the POST request should be a JSON object with the following fields:

  • enabled: A boolean value to enable or disable the configuration
  • body: A string value which contains the content of the configuration file

The scopes are (not yet implemented):

  • read: github.com/mutablelogic/go-server/handler/nginx.read
  • write: github.com/mutablelogic/go-server/handler/nginx.write

# Packages

Implements an API client for the nginx API (https://github.com/mutablelogic/go-server/pkg/handler/nginx) */.
No description provided by the author
Manages the lifecycle of configuration folders for nginx */.

# Functions

Create a new http server from the configuration.

# Structs

No description provided by the author

# Interfaces

No description provided by the author