api

package
v0.0.0-...-93ea978 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	Config Config
	Logger *log.Logger
}

func (*API) ErrorResponse

func (api *API) ErrorResponse(w http.ResponseWriter, r *http.Request, status int, message interface{})

The errorResponse() method is a generic helper for sending JSON-formatted error messages to the client with a given status code. Note that we're using an interface{} type for the message parameter, rather than just a string type, as this gives us more flexibility over the values that we can include in the response.

func (*API) GetIpHandler

func (api *API) GetIpHandler(w http.ResponseWriter, r *http.Request)

func (*API) GetIpInfoHandler

func (api *API) GetIpInfoHandler(w http.ResponseWriter, r *http.Request)

func (*API) HealthcheckHandler

func (api *API) HealthcheckHandler(w http.ResponseWriter, r *http.Request)

func (*API) LogError

func (api *API) LogError(r *http.Request, err error)

func (*API) MethodNotAllowedResponse

func (api *API) MethodNotAllowedResponse(w http.ResponseWriter, r *http.Request)

The methodNotAllowedResponse() method will be used to send a 405 Method Not Allowed status code and JSON response to client

func (*API) NotFoundResponse

func (api *API) NotFoundResponse(w http.ResponseWriter, r *http.Request)

The notFoundResponse() method will be used to send 404 Not Found status code and JSON response to the client.

func (*API) Routes

func (api *API) Routes() http.Handler

func (*API) Serve

func (api *API) Serve() error

func (*API) ServerErrorResponse

func (api *API) ServerErrorResponse(w http.ResponseWriter, r *http.Request, err error)

The serverErrorResponse() method will be used when our application encounters an unexpected problem at runtime. It logs the detailed error message, then uses the errorResponse() helper to send a 500 Internal Server Error status code and JSON response (containing a generic error message) to the client.

func (*API) WriteJSON

func (api *API) WriteJSON(w http.ResponseWriter, status int, data Envelope, headers http.Header) error

Define a WriteJSON helper for sending responses.

func (*API) WritePlainText

func (api *API) WritePlainText(w http.ResponseWriter, status int, body string, headers http.Header) error

Define WritePlainText helper for sending responses.

type Config

type Config struct {
	Port              int
	IpinfoAccessToken string
}

type Envelope

type Envelope map[string]interface{}

Define an evelope type.

Jump to

Keyboard shortcuts

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