🚀 Launch Week Day 4:Introducing the Alert Details Page: A Better Way to Explore Alerts.Learn More →
Socket
Book a DemoInstallSign in
Socket

southwinds.dev/http

Package Overview
Dependencies
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

southwinds.dev/http

Go Modules
Version
v0.0.0-20230111144446-0b0c44c82c58
Version published
Created
Source

HTTP Server Library

The HTTP server library helps to quickly create a consistent HTTP server with some useful middlewares, OpenAPI, Prometheus metrics and standard access controls.

The server is focused on serving REST style APIs and is based on the Gorilla Mux request router and dispatcher.

Getting started

Add the module to your project:

$  go get southwinds.dev/http

Set up the server:

package main

import (
    "github.com/gorilla/mux"
    "net/http"
    h "southwinds.dev/http"
)

func main() {
    // create a new server
    server := h.New("test")
    // configure http handlers
    server.Http = func(router *mux.Router) {
        // add basic authentication
        router.Use(server.AuthenticationMiddleware)
        // add handler
        router.HandleFunc("/", doSomething).Methods("GET")
    }
    server.Serve()
}

func doSomething(writer http.ResponseWriter, request *http.Request) {
    writer.WriteHeader(http.StatusOK)
}

For a more complete example see here.

Configuratiion

The server can be configured via the following environment variables:

namedescriptiondefault
HTTP_METRICS_ENABLEDenables Prometheus endpoint at /metricstrue
HTTP_OPEN_API_ENABLEDenables Swagger enpoint at /api/true
HTTP_PORTport on which the server listen8080
HTTP_USERbasic authentication user nameadmin
HTTP_PASSWORDbasic authentication passwordauto-generated
HTTP_REALMthe realm name for browser WWW-Authenticate promptnone

FAQs

Package last updated on 11 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts