api

package
v0.0.0-...-7002d4d Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HeartbeatHandler

func HeartbeatHandler(w http.ResponseWriter, r *http.Request)

HeartbeatHandler checks the health of the service. For simplicity, we'll just send an "OK" response.

func StringArrayContains

func StringArrayContains(arr []string, str string) bool

StringArrayContains helper function to return true or false is a given string exists in the provided string array

Types

type APIRoute

type APIRoute struct {
	Version  uint8                                    // 0 = v1, 1 = v2, etc.
	SubRoute string                                   // e.g. "users", "posts","products", etc.
	Name     string                                   // e.g. "get", "create", "update", "delete", etc.
	Method   string                                   // e.g. "GET", "POST", "PUT", "DELETE", etc.
	Handler  func(http.ResponseWriter, *http.Request) // e.g. GetUsersHandler, CreateUsersHandler, etc.
}

APIRoute is a struct to represent an API route.

type APIServer

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

APIServer is a struct to represent the API server.

var (
	// Server is the global value for the API server
	Server *APIServer
)

func (*APIServer) AddAuthorizedRemote

func (s *APIServer) AddAuthorizedRemote(remote string)

AddAuthorizedRemote adds an authorized remote to the API server.

func (*APIServer) AddRoute

func (s *APIServer) AddRoute(route *APIRoute)

AddRoute adds a route to the API server. Example:

Server.AddRoute(&APIRoute{
	version:  1,
	subRoute: "users",
	name:     "get",
	method:   "GET",
	handler:  GetUsersHandler,
})

func (*APIServer) GetAuthorizedRemotes

func (s *APIServer) GetAuthorizedRemotes() []string

GetAuthorizedRemotes returns the list of authorized remotes (IP Addresses).

func (*APIServer) GetCertFolder

func (s *APIServer) GetCertFolder() string

GetCertFolder returns the path to the TLS certificates.

func (*APIServer) GetPort

func (s *APIServer) GetPort() string

GetPort returns the port number for the API server.

func (*APIServer) GetRouter

func (s *APIServer) GetRouter() *mux.Router

GetRouter returns the router object.

func (*APIServer) GetServer

func (s *APIServer) GetServer() *http.Server

GetServer returns the HTTP/2 server object.

func (*APIServer) Initialize

func (s *APIServer) Initialize(port string, certFolder string)

startServer starts the HTTP/2 server in a goroutine.

func (*APIServer) Start

func (s *APIServer) Start()

Start starts the HTTP/2 server in a goroutine. It then calls waitForShutdown() to block until the server is stopped.

func (*APIServer) Stop

func (s *APIServer) Stop()

Stop stops the HTTP/2 server.

Jump to

Keyboard shortcuts

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