rest

package
v1.2.7 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2025 License: MIT Imports: 28 Imported by: 3

README

Rest Server

The server package provides a simple and efficient way to expose server side RESTful APIs in Go. This package is built on top of the oss.nandlabs.io/golly/turbo package and provides a simple way to define routes and handle requests and maintain the configuration & lifecycle of the server.



Features

Client Features
  • HTTP methods: GET, POST, PUT, DELETE
  • Query parameters
  • Request headers
  • Retry
  • CircuitBreaker Configuration
  • Proxy Configuration
  • TLS Configuration
  • Transport Layer Configuration
    • MaxIdle Connections
    • Connection Timeout
    • TLS Handshake Timeout
  • SSL Verification and Configuration
  • CA Certs Configuration
  • Error handling
    • ErrorOnHttpStatus : sets the list of status codes that can be considered failures
Server Features
  • HTTP methods: GET, POST, PUT, DELETE
  • Query parameters
  • Request headers
  • TLS Configuration
  • Transport Layer Configuration
    • Connection Timeout
    • Read Timeout

Installation

To install the REST server, use the following command:

go get oss.nandlabs.io/golly/rest

Usage

Client
HTTP Methods : Sending a GET Request
package main

import (
  "fmt"
  "oss.nandlabs.io/golly/rest/client"
)

func main() {
  client := rest.NewClient()
  req := client.NewRequest("http://localhost:8080/api/v1/getData", "GET")
  res, err := client.Execute(req)
  if err != nil {
    // handle error
    fmt.Errorf("error executing request: %v", err)
  }
  // handle response
  fmt.Println(res)
}
Retry Configuration
package main

import (
  "fmt"
  "oss.nandlabs.io/golly/clients/rest"
)

func main() {
  client := rest.NewClient()
  req := client.NewRequest("http://localhost:8080/api/v1/getData", "GET")
  // maxRetries -> 3, wait -> 5 seconds
  client.Retry(3, 5)
  res, err := client.Execute(req)
  if err != nil {
    // handle error
    fmt.Errorf("error executing request: %v", err)
  }
  // handle response
  fmt.Println(res)
}
CircuitBreaker Configuration
package main

import (
  "fmt"
  "oss.nandlabs.io/golly/clients/rest"
)

func main() {
  client := rest.NewClient()
  req := client.NewRequest("http://localhost:8080/api/v1/getData", "GET")
  client.UseCircuitBreaker(1, 2, 1, 3)
  res, err := client.Execute(req)
  if err != nil {
    // handle error
    fmt.Errorf("error executing request: %v", err)
  }
  // handle response
  fmt.Println(res)
}
Proxy Configuration
package main

import (
  "fmt"
  "oss.nandlabs.io/golly/clients/rest"
)

func main() {
  client := rest.NewClient()
  req := client.NewRequest("http://localhost:8080/api/v1/getData", "GET")
  err := client.SetProxy("proxy:url", "proxy_user", "proxy_pass")
  if err != nil {
	  fmt.Errorf("unable to set proxy: %v", err)
  }
  res, err := client.Execute(req)
  if err != nil {
    // handle error
    fmt.Errorf("error executing request: %v", err)
  }
  // handle response
  fmt.Println(res)
}
TLS Configuration
package main

import (
  "crypto/tls"
  "fmt"
  "oss.nandlabs.io/golly/clients/rest"
)

func main() {
  client := rest.NewClient()
  req := client.NewRequest("http://localhost:8080/api/v1/getData", "GET")
  client, err := client.SetTLSCerts(tls.Certificate{})
  if err != nil {
    fmt.Errorf("error adding tls certificates: %v", err)
  }
  res, err := client.Execute(req)
  if err != nil {
    // handle error
    fmt.Errorf("error executing request: %v", err)
  }
  // handle response
  fmt.Println(res)
}
SSL Verification and CA Certs Configuration
package main

import (
  "fmt"
  "oss.nandlabs.io/golly/clients/rest"
)

func main() {
  client := rest.NewClient()
  req := client.NewRequest("http://localhost:8080/api/v1/getData", "GET")
  client, err := client.SSlVerify(true)
  if err != nil {
	  fmt.Errorf("unable to set ssl verification, %v", err)
  }
  client, err = client.SetCACerts("./test-cert.pem", "./test-cert-2.pem")
  if err != nil {
    fmt.Errorf("error adding ca certificates: %v", err)
  }
  res, err := client.Execute(req)
  if err != nil {
    // handle error
    fmt.Errorf("error executing request: %v", err)
  }
  // handle response
  fmt.Println(res)
}
Server
HTTP Methods : Serve a GET Request
package main

import (
	"net/http"

	"oss.nandlabs.io/golly/lifecycle"
	"oss.nandlabs.io/golly/rest"
)

func main() {
	// Create a new server
	// Checkout  New(opts *SrvOptions) for customisng the server properties
	srv, err := rest.DefaultServer()
	if err != nil {
		panic(err)
	}
	// this is the path prefix for each endpoint. Default is empty and no path prefix is added
	srv.Opts().PathPrefix = "/api/v1"
	// Add a GET endpoint
	srv.Get("healthCheck", func(ctx rest.ServerContext) {
		// Set the status code. Remember to set the status code before writing the response
		ctx.SetStatusCode(http.StatusOK)
		ctx.WriteString("Health Check Get")
	})
	// Add a POST endpoint
	srv.Post("healthCheck", func(ctx rest.ServerContext) {
		input, _ := ctx.GetBody()
		// Set the status code. Remember to set the status code before writing the response
		ctx.SetStatusCode(http.StatusOK)
		// Write the response
		ctx.WriteFrom(input)
	})
	// get the component manager
	mgr := lifecycle.NewSimpleComponentManager()
	// Register the server with the component manager
	mgr.Register(srv)
	// Start the server
	mgr.StartAndWait()
}

Serve a Post Request
package main

import (
	"net/http"

	"oss.nandlabs.io/golly/lifecycle"
	"oss.nandlabs.io/golly/rest"
)

func main() {
	// Create a new server
	// Checkout  New(opts *Options) for customisng the server properties
	srv, err := rest.DefaultServer()
	if err != nil {
		panic(err)
	}
	// this is the path prefix for each endpoint. Default is empty and no path prefix is added
	srv.Opts().PathPrefix = "/api/v1"
	// Add a POST endpoint
	srv.Post("healthCheck", func(ctx rest.ServerContext) {
		input, _ := ctx.GetBody()
		// Set the status code. Remember to set the status code before writing the response
		ctx.SetStatusCode(http.StatusOK)
		// Write the response
		ctx.WriteFrom(input)
	})
	// get the component manager
	mgr := lifecycle.NewSimpleComponentManager()
	// Register the server with the component manager
	mgr.Register(srv)
	// Start the server
	mgr.StartAndWait()
}

Serve a Put Request
package main

import (
	"net/http"

	"oss.nandlabs.io/golly/lifecycle"
	"oss.nandlabs.io/golly/rest"
)

func main() {
	// Create a new server
	// Checkout  New(opts *Options) for customisng the server properties
	srv, err := rest.DefaultServer()
	if err != nil {
		panic(err)
	}
	// this is the path prefix for each endpoint. Default is empty and no path prefix is added
	srv.Opts().PathPrefix = "/api/v1"
	// Add a PUT endpoint
	srv.Put("healthCheck", func(ctx rest.ServerContext) {
		input, _ := ctx.GetBody()
		// Set the status code. Remember to set the status code before writing the response
		ctx.SetStatusCode(http.StatusOK)
		// Write the response
		ctx.WriteFrom(input)
	})
	// get the component manager
	mgr := lifecycle.NewSimpleComponentManager()
	// Register the server with the component manager
	mgr.Register(srv)
	// Start the server
	mgr.StartAndWait()
}

Serve a Delete Request
package main

import (
	"net/http"

	"oss.nandlabs.io/golly/lifecycle"
	"oss.nandlabs.io/golly/rest"
)

func main() {
	// Create a new server
	// Checkout  New(opts *Options) for customisng the server properties
	srv, err := rest.DefaultServer()
	if err != nil {
		panic(err)
	}
	// this is the path prefix for each endpoint. Default is empty and no path prefix is added
	srv.Opts().PathPrefix = "/api/v1"
	// Add a DELETE endpoint
	srv.Delete("healthCheck", func(ctx rest.ServerContext) {
		input, _ := ctx.GetBody()
		// Set the status code. Remember to set the status code before writing the response
		ctx.SetStatusCode(http.StatusOK)
		// Write the response
		ctx.WriteFrom(input)
	})
	// get the component manager
	mgr := lifecycle.NewSimpleComponentManager()
	// Register the server with the component manager
	mgr.Register(srv)
	// Start the server
	mgr.StartAndWait()
}

Serve a Request with Parameters
package main

import (
	"net/http"

	"oss.nandlabs.io/golly/lifecycle"
	"oss.nandlabs.io/golly/rest"
)

func main() {
	// Create a new server
	// Checkout  New(opts *Options) for customisng the server properties
	srv, err := rest.DefaultServer()
	if err != nil {
		panic(err)
	}
	// this is the path prefix for each endpoint. Default is empty and no path prefix is added
	srv.Opts().PathPrefix = "/api/v1"
	// Add a GET endpoint
	srv.Get("endpoint/:pathparam", func(ctx rest.ServerContext) {
		// Get the query parameters
		queryParams := ctx.GetParam("paramName",rest.QueryParam)
		// Get the path parameters
		pathParams := ctx.GetParam("pathparam",rest.PathParam)
		// Do something with the query parameters and pathParameters
	})
	// get the component manager
	mgr := lifecycle.NewSimpleComponentManager()
	// Register the server with the component manager
	mgr.Register(srv)
	// Start the server
	mgr.StartAndWait()
}

Documentation

See rest package documentation for more details.

Documentation

Overview

Package rest provides a set of utilities for making RESTful API calls.

This package includes functions for sending HTTP requests, handling responses, and managing authentication and authorization headers.

Example usage:

// Create a new REST client
client := rest.NewClient()

// Set the base URL for the API
client.SetBaseURL("https://api.example.com")

// Set the authentication token
client.SetAuthToken("YOUR_AUTH_TOKEN")

// Send a GET request
response, err := client.Get("/users")
if err != nil {
    log.Fatal(err)
}

// Print the response body
fmt.Println(response.Body)

// Close the response body
response.Close()

For more information and examples, please refer to the package documentation.

Index

Constants

View Source
const (
	// ContentTypeHeader
	ContentTypeHeader = "Content-Type"
	// JSONContentType
	JSONContentType = "application/json"
	// XMLContentType
	XMLContentType = "text/xml"
	// XmlApplicationContentType
	XmlApplicationContentType = "application/xml"
	// YAMLContentType
	YAMLContentType = "text/yaml"

	// ProxyAuthorizationHeader
	ProxyAuthorization = "Proxy-Authorization"
	// AuthorizationHeader
	Authorization
	// AcceptHeader
	AcceptHeader = "Accept"
	// AcceptEncodingHeader
	AcceptEncodingHeader = "Accept-Encoding"
	// AcceptLanguageHeader
	AcceptLanguageHeader = "Accept-Language"

	// PathSeparator
	PathSeparator = "/"
)

Variables

View Source
var ErrInvalidCertPath = errors.New("empty cert path")
View Source
var ErrInvalidConfig = errors.New("empty config path")
View Source
var ErrInvalidID = errors.New("empty id")
View Source
var ErrInvalidListenHost = errors.New("empty listen host")
View Source
var ErrInvalidListenPort = errors.New("empty listen port")
View Source
var ErrInvalidParamType = errors.New("invalid param type provided")
View Source
var ErrInvalidPrivateKeyPath = errors.New("empty private key path")
View Source
var ErrNilOptions = errors.New("nil options")

Functions

func CreateMultipartHeader added in v1.2.0

func CreateMultipartHeader(param, fileName, contentType string) textproto.MIMEHeader

CreateMultipartHeader creates a multipart header with the given parameters

func IsValidMultipartVerb added in v1.2.0

func IsValidMultipartVerb(method string) (err error)

IsValidMultipartVerb checks if the method is valid for multipart content

func WriteMultipartFormFile added in v1.2.0

func WriteMultipartFormFile(w *multipart.Writer, fieldName, fileName string, r io.Reader) error

WriteMultipartFormFile writes a multipart form file to the writer

Types

type AuthHandlerFunc added in v1.2.6

type AuthHandlerFunc func(client *Client, req *http.Request) error

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents a REST client.

func NewClient

func NewClient() *Client

NewClient creates a new REST client with default values.

func NewClientWithOptions added in v1.2.6

func NewClientWithOptions(options *ClientOpts) *Client

func (*Client) Close

func (c *Client) Close() (err error)

Close closes all idle connections that are available.

func (*Client) Execute

func (c *Client) Execute(req *Request) (res *Response, err error)

Execute sends the client request and returns the response object.

func (*Client) NewRequest

func (c *Client) NewRequest(reqUrl, method string) (req *Request, err error)

NewRequest creates a new request object for the client.

type ClientOpts added in v1.2.6

type ClientOpts struct {
	*clients.ClientOptions

	AuthHandlers map[clients.AuthType]AuthHandlerFunc
	// contains filtered or unexported fields
}

type ClientOptsBuilder added in v1.2.6

type ClientOptsBuilder struct {
	*clients.OptionsBuilder
	// contains filtered or unexported fields
}

func CliOptsBuilder added in v1.2.6

func CliOptsBuilder() *ClientOptsBuilder

func (*ClientOptsBuilder) BaseUrl added in v1.2.6

func (co *ClientOptsBuilder) BaseUrl(baseurl string) (err error)

func (*ClientOptsBuilder) Build added in v1.2.6

func (co *ClientOptsBuilder) Build() *ClientOpts

func (*ClientOptsBuilder) CaCerts added in v1.2.6

func (co *ClientOptsBuilder) CaCerts(caFilePath ...string) *ClientOptsBuilder

func (*ClientOptsBuilder) CodecOpts added in v1.2.6

func (co *ClientOptsBuilder) CodecOpts(options map[string]any) *ClientOptsBuilder

func (*ClientOptsBuilder) CookieJar added in v1.2.6

func (co *ClientOptsBuilder) CookieJar(jar http.CookieJar) *ClientOptsBuilder

func (*ClientOptsBuilder) EnvProxy added in v1.2.6

func (co *ClientOptsBuilder) EnvProxy(proxyBasicAuth string) *ClientOptsBuilder

func (*ClientOptsBuilder) ErrOnStatus added in v1.2.6

func (co *ClientOptsBuilder) ErrOnStatus(httpStatusCodes ...int) *ClientOptsBuilder

func (*ClientOptsBuilder) ExpectContinueTimeoutMs added in v1.2.6

func (co *ClientOptsBuilder) ExpectContinueTimeoutMs(t int) *ClientOptsBuilder

func (*ClientOptsBuilder) IdleTimeoutMs added in v1.2.6

func (co *ClientOptsBuilder) IdleTimeoutMs(t int) *ClientOptsBuilder

func (*ClientOptsBuilder) MaxIdlePerHost added in v1.2.6

func (co *ClientOptsBuilder) MaxIdlePerHost(maxIdleConnPerHost int) *ClientOptsBuilder

func (*ClientOptsBuilder) ProxyAuth added in v1.2.6

func (co *ClientOptsBuilder) ProxyAuth(user, password, bypass string) *ClientOptsBuilder

func (*ClientOptsBuilder) RequestTimeoutMs added in v1.2.6

func (co *ClientOptsBuilder) RequestTimeoutMs(t int) *ClientOptsBuilder

func (*ClientOptsBuilder) SSLVerify added in v1.2.6

func (co *ClientOptsBuilder) SSLVerify(verify bool) *ClientOptsBuilder

func (*ClientOptsBuilder) TlsCerts added in v1.2.6

func (co *ClientOptsBuilder) TlsCerts(certs ...tls.Certificate) *ClientOptsBuilder

func (*ClientOptsBuilder) TlsHandShakeTimeoutMs added in v1.2.6

func (co *ClientOptsBuilder) TlsHandShakeTimeoutMs(t int) *ClientOptsBuilder

type HandlerFunc added in v1.2.0

type HandlerFunc func(context ServerContext)

type MultipartFile

type MultipartFile struct {
	ParamName string
	FilePath  string
}

type Paramtype added in v1.2.0

type Paramtype int
const (
	QueryParam Paramtype = iota
	PathParam
)

type Request

type Request struct {
	// contains filtered or unexported fields
}

Request struct holds the http Request for the rest client

func (*Request) AddFormData

func (r *Request) AddFormData(k string, v ...string) *Request

AddFormData function adds the form data with the name specified by k list of values in order as specified in v If the key does not exist then it creates a new form data by calling url.Values.Set() function on the first key and the value Setting form data will have precedence over to setting body directly.

func (*Request) AddHeader

func (r *Request) AddHeader(k string, v ...string) *Request

func (*Request) AddPathParam

func (r *Request) AddPathParam(k string, v string) *Request

AddPathParam function adds the path parameter with key as the name of the parameter and v as the value of the parameter that needs to be replaced

func (*Request) AddQueryParam

func (r *Request) AddQueryParam(k string, v ...string) *Request

AddQueryParam function adds the query parameter with the name specified by k list of values in order as specified in v If the key does not exist then it creates a new form data by calling url.Values.Set() function passing the first key and value

func (*Request) Method

func (r *Request) Method() string

Method function prints the current method for this Request

func (*Request) SeBodyReader

func (r *Request) SeBodyReader(reader io.Reader) *Request

func (*Request) SetBody

func (r *Request) SetBody(v interface{}) *Request

func (*Request) SetContentType

func (r *Request) SetContentType(contentType string) *Request

func (*Request) SetMultipartFiles

func (r *Request) SetMultipartFiles(files ...*MultipartFile) *Request

type Response

type Response struct {
	// contains filtered or unexported fields
}

func (*Response) Decode

func (r *Response) Decode(v interface{}) (err error)

Decode Function decodes the response body to a suitable object. The format of the body is determined by Content-Type header in the response

func (*Response) GetError

func (r *Response) GetError() (err error)

GetError gets the error with status code and value

func (*Response) IsSuccess

func (r *Response) IsSuccess() bool

IsSuccess determines if the response is a success response

func (*Response) Raw

func (r *Response) Raw() *http.Response

Raw Provides the backend raw response

func (*Response) Status

func (r *Response) Status() string

Status Provides status text of the http response

func (*Response) StatusCode

func (r *Response) StatusCode() int

StatusCode provides the status code of the response

type Server added in v1.2.0

type Server interface {
	// Server is a lifecytcle component
	lifecycle.Component
	// Opts returns the options of the server
	Opts() *SrvOptions
	// AddRoute adds a route to the server
	AddRoute(path string, handler HandlerFunc, method ...string) (route *turbo.Route, err error)
	// AddRoute adds a route to the server
	Post(path string, handler HandlerFunc) (route *turbo.Route, err error)
	// AddRoute adds a route to the server
	Get(path string, handler HandlerFunc) (route *turbo.Route, err error)
	// AddRoute adds a route to the server
	Put(path string, handler HandlerFunc) (route *turbo.Route, err error)
	// AddRoute adds a route to the server
	Delete(path string, handler HandlerFunc) (route *turbo.Route, err error)
	// Unhandled adds a handler for unhandled routes
	Unhandled(handler HandlerFunc) (err error)
	// Unsupported adds a handler for unsupported methods
	Unsupported(handler HandlerFunc) (err error)
	// AddGlobalFilter adds a global filter to the server
	AddGlobalFilter(filter turbo.FilterFunc) (err error)
	//Turbo returns the turbo router
	Router() *turbo.Router
}

Server is the interface that wraps the ServeHTTP method.

func DefaultServer added in v1.2.0

func DefaultServer() (Server, error)

DefaultServer creates a new Server with the default options.

func NewServer added in v1.2.0

func NewServer(opts *SrvOptions) (rServer Server, err error)

NewServer creates a new Server with the given options.

func NewServerFrom added in v1.2.0

func NewServerFrom(configPath string) (Server, error)

New creates a new Server with the given configuration file of the options.

type ServerContext added in v1.2.1

type ServerContext struct {
	// contains filtered or unexported fields
}

ServerContext is the struct that holds the request and response of the server.

func (*ServerContext) GetBody added in v1.2.1

func (c *ServerContext) GetBody() (io.Reader, error)

GetBody returns the body of the request.

func (*ServerContext) GetHeader added in v1.2.1

func (c *ServerContext) GetHeader(name string) string

GetHeader returns the header of the request.

func (*ServerContext) GetMethod added in v1.2.1

func (c *ServerContext) GetMethod() string

GetMethod returns the method of the request.

func (*ServerContext) GetParam added in v1.2.1

func (c *ServerContext) GetParam(name string, typ Paramtype) (string, error)

Options is the struct that holds the configuration for the Server.

func (*ServerContext) GetRequest added in v1.2.1

func (c *ServerContext) GetRequest() *http.Request

GetRequest returns the request. for most Rest Use cases this would not be required

func (*ServerContext) GetURL added in v1.2.1

func (c *ServerContext) GetURL() string

GetURL returns the URL of the request.

func (*ServerContext) HttpResWriter added in v1.2.1

func (c *ServerContext) HttpResWriter() http.ResponseWriter

HttpResWriter returns the http.ResponseWriter

func (*ServerContext) InHeaders added in v1.2.1

func (c *ServerContext) InHeaders() http.Header

InHeaders returns the headers of the request.

func (*ServerContext) Read added in v1.2.1

func (c *ServerContext) Read(obj interface{}) error

Read reads the body of the request into the given object.

func (*ServerContext) SetContentType added in v1.2.1

func (c *ServerContext) SetContentType(contentType string)

SetContentType sets the content type of the response.

func (*ServerContext) SetCookie added in v1.2.1

func (c *ServerContext) SetCookie(cookie *http.Cookie)

SetCookie sets the cookie of the response.

func (*ServerContext) SetHeader added in v1.2.1

func (c *ServerContext) SetHeader(name, value string)

SetHeader sets the header of the response.

func (*ServerContext) SetStatusCode added in v1.2.1

func (c *ServerContext) SetStatusCode(statusCode int)

SetStatusCode sets the status code of the response.

func (*ServerContext) Write added in v1.2.1

func (c *ServerContext) Write(data interface{}, contentType string) error

Write writes the object to the response with the given content type and status code.

func (*ServerContext) WriteData added in v1.2.1

func (c *ServerContext) WriteData(data []byte) (int, error)

WriteData writes the data to the response.

func (*ServerContext) WriteFrom added in v1.2.1

func (c *ServerContext) WriteFrom(data io.Reader)

WriteFrom writes the data from the reader to the response.

func (*ServerContext) WriteJSON added in v1.2.1

func (c *ServerContext) WriteJSON(data interface{}) error

WriteJSON writes the object to the response in JSON format.

func (*ServerContext) WriteString added in v1.2.1

func (c *ServerContext) WriteString(data string)

WriteString writes the string to the response.

func (*ServerContext) WriteXML added in v1.2.1

func (c *ServerContext) WriteXML(data interface{}) error

WriteXML writes the object to the response in XML format.

func (*ServerContext) WriteYAML added in v1.2.1

func (c *ServerContext) WriteYAML(data interface{}) error

WriteYAML writes the object to the response in YAML format.

type SrvOptions added in v1.2.0

type SrvOptions struct {
	Id             string               `json:"id" yaml:"id" bson:"id" mapstructure:"id"`
	PathPrefix     string               `json:"path_prefix,omitempty" yaml:"path_prefix,omitempty" bson:"path_prefix,omitempty" mapstructure:"path_prefix,omitempty"`
	ListenHost     string               `json:"listen_host" yaml:"listen_host" bson:"listen_host" mapstructure:"listen_host"`
	ListenPort     int16                `json:"listen_port" yaml:"listen_port" bson:"listen_port" mapstructure:"listen_port"`
	ReadTimeout    int64                `` /* 127-byte string literal not displayed */
	WriteTimeout   int64                `` /* 131-byte string literal not displayed */
	EnableTLS      bool                 `json:"enable_tls" yaml:"enable_tls" bson:"enable_tls" mapstructure:"enable_tls"`
	PrivateKeyPath string               `` /* 138-byte string literal not displayed */
	CertPath       string               `json:"cert_path,omitempty" yaml:"cert_path,omitempty" bson:"cert_path,omitempty" mapstructure:"cert,omitempty"`
	Cors           *filters.CorsOptions `json:"cors,omitempty" yaml:"cors,omitempty" bson:"cors,omitempty" mapstructure:"cors,omitempty"`
}

SrvOptions is the configuration for the server

func DefaultSrvOptions added in v1.2.0

func DefaultSrvOptions() *SrvOptions

DefaultSrvOptions returns the default options for the server The default options are:

  • PathPrefix: "/"
  • Id: "default-http-server"
  • ListenHost: "localhost"
  • ListenPort: 8080
  • ReadTimeout: 20000
  • WriteTimeout: 20000
  • Cors: &filters.CorsOptions{ MaxAge: 0, AllowedOrigins: []string{"*"}, AllowedMethods: []string{"GET", "POST", "PUT", "DELETE"}, ResponseStatus: http.StatusNoContent, }

func EmptySrvOptions added in v1.2.0

func EmptySrvOptions() *SrvOptions

EmptySrvOptions returns a new server options

func (*SrvOptions) GetCertPath added in v1.2.0

func (o *SrvOptions) GetCertPath() string

GetCertPath returns the cert path

func (*SrvOptions) GetEnableTLS added in v1.2.0

func (o *SrvOptions) GetEnableTLS() bool

GetEnableTLS returns the enable TLS value

func (*SrvOptions) GetListenHost added in v1.2.0

func (o *SrvOptions) GetListenHost() string

GetListenHost returns the listen host

func (*SrvOptions) GetListenPort added in v1.2.0

func (o *SrvOptions) GetListenPort() int16

GetListenPort returns the listen port

func (*SrvOptions) GetPrivateKeyPath added in v1.2.0

func (o *SrvOptions) GetPrivateKeyPath() string

GetPrivateKeyPath returns the private key path

func (*SrvOptions) SetCertPath added in v1.2.0

func (o *SrvOptions) SetCertPath(certPath string) *SrvOptions

SetCertPath sets the cert path

func (*SrvOptions) SetEnableTLS added in v1.2.0

func (o *SrvOptions) SetEnableTLS(enableTLS bool) *SrvOptions

SetEnableTLS sets the enable TLS value

func (*SrvOptions) SetListenHost added in v1.2.0

func (o *SrvOptions) SetListenHost(host string) *SrvOptions

SetListenHost sets the listen host

func (*SrvOptions) SetListenPort added in v1.2.0

func (o *SrvOptions) SetListenPort(port int16) *SrvOptions

SetListenPort sets the listen port

func (*SrvOptions) SetPrivateKeyPath added in v1.2.0

func (o *SrvOptions) SetPrivateKeyPath(privateKeyPath string) *SrvOptions

SetPrivateKeyPath sets the private key path

func (*SrvOptions) Validate added in v1.2.0

func (o *SrvOptions) Validate() error

Validate validates the server options

Jump to

Keyboard shortcuts

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