server

package module
v0.0.0-...-784eaf7 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2023 License: MIT Imports: 6 Imported by: 0

README

Go Server

There are many like it, but this one is mine.

A convenience wrapper to start a new HTTP server.

Example Usage

package main

import (
	"fmt"
	"html"
	"net/http"
	"os"

	server "git.sr.ht/~jswank/go-server"
	"github.com/rs/zerolog"
)

func main() {

	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
	})

	//  address := ":8090"
	logger := zerolog.New(os.Stderr).With().Timestamp().Logger()
	//	tls_cert := "/path/to/cert"
	//	tls_key := "/path/to/key"
	//	mux := http.DefaultServeMux

	s := server.NewServer(
		// server.SetAddress(address),
		server.SetLogger(logger),
		//		server.SetCert(tls_cert),
		//		server.SetKey(tls_key),
		//		server.SetHandler(mux),
	)

	s.ListenAndServe()

}

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetAddress

func SetAddress(address string) optionFunc

func SetCert

func SetCert(cert string) optionFunc

func SetHandler

func SetHandler(handler http.Handler) optionFunc

func SetKey

func SetKey(key string) optionFunc

func SetLogger

func SetLogger(log zerolog.Logger) optionFunc

Types

type Server

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

func NewServer

func NewServer(optionFuncs ...optionFunc) *Server

func (*Server) ListenAndServe

func (s *Server) ListenAndServe()

func (*Server) NewListener

func (s *Server) NewListener() (net.Listener, error)

func (*Server) ServeHTTP

func (s *Server) ServeHTTP()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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