🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

kumoly.io/lib/ksrv

Package Overview
Dependencies
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kumoly.io/lib/ksrv

Go Modules
Version
v0.0.1
Version published
Created
Source

ksrv

A extended http.Server with logging and panic recovery

Examples

package main

import (
	"errors"
	"fmt"
	"net/http"

	"kumoly.io/core/log"
	"kumoly.io/lib/ksrv"
)

func main() {
	log.PROD = false
	mux := http.NewServeMux()
	mux.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) { rw.Write([]byte("ok")) })
	mux.HandleFunc("/err", func(rw http.ResponseWriter, r *http.Request) { ksrv.Abort(rw, errors.New("small err")) })
	mux.HandleFunc("/panic", func(rw http.ResponseWriter, r *http.Request) { panic(500) })
	mux.HandleFunc("/out", func(rw http.ResponseWriter, r *http.Request) { arr := []int{0, 1}; fmt.Print(arr[9]) })
	log.Info("start")

	err := ksrv.New().Handle(mux).Listen("0.0.0.0:8080").Serve()
	if err != nil {
		panic(err)
	}
}

FAQs

Package last updated on 05 Nov 2021

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