basicServer

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: AGPL-3.0 Imports: 5 Imported by: 0

README

��# golang-basicServer

This package makes it easy to create an HTTPS server (alongside an HTTP server that will redirect to the more secure one).

Example

package main

import (
	"net/http"
	"time"

	basicServer "github.com/theTardigrade/golang-basicServer"
)

const (
	output = "<!DOCTYPE><html><body><h1>THIS IS AN EXAMPLE</h1></body></html>"
)

var (
	opts = basicServer.Options{
		HttpPort:                80,
		HttpsPort:               443,
		ResponseTimeoutDuration: 60 * time.Second,
		RequestTimeoutDuration:  60 * time.Second,
		CertFilePath:            "/example/certificates/default.cer",
		KeyFilePath:             "/example/certificates/default.key",
		Routes: basicServer.OptionsRoutes{
			Get: map[string]http.Handler{
				"/": http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
					resp.Header().Set("Content-Type", "text/html")
					resp.WriteHeader(http.StatusOK)
					resp.Write([]byte(output))
				}),
			},
		},
	}
)

func main() {
	basicServer.ServeContinuously(opts, func(err error) {
		log.Println(err)
	})
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Serve

func Serve(opts Options) (err error)

func ServeContinuously

func ServeContinuously(opts Options, errHandler func(error))

func ValueFromRequest added in v1.0.4

func ValueFromRequest(r *http.Request, key string) string

func ValuesMapFromRequest added in v1.0.4

func ValuesMapFromRequest(r *http.Request) map[string]string

Types

type Options

type Options = options.Datum

type OptionsMiddleware added in v1.0.3

type OptionsMiddleware = options.DatumMiddleware

type OptionsMiddlewareHandler added in v1.0.3

type OptionsMiddlewareHandler = options.DatumMiddlewareHandler

type OptionsRoutes

type OptionsRoutes = options.DatumRoutes

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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