gowebserver

module
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2021 License: Apache-2.0

README

Go Web Server

A simple, convenient, reliable, well tested HTTP/HTTPS web server to host static files. It can host a local directory or contents of a zip file.

# Download (linux amd64, see Downloads for other builds)
curl -o gowebserver -O -L https://github.com/jeremyje/gowebserver/releases/download/v1.10.0/server-amd64; chmod +x gowebserver

# Host the directory you're currently in.
./gowebserver

# Host your home directory.
./gowebserver --path=${HOME}

# Host a zip file from the internet.
./gowebserver --path=https://github.com/jeremyje/gowebserver/archive/v1.10.0.zip

Features

  • Zero-config required, hosts on port 80 or 8080 based on root and supports Cloud9's $PORT variable.
  • HTTP and HTTPs serving
  • Automatic HTTPs certificate generation
  • Optional configuration by flags or YAML config file.
  • Host static files from:
    • Local directory (current directory is default)
    • ZIP archive (local or from HTTP/HTTPS)
    • Tarball (.tar, .tar.gz, .tar.bz2) archive
    • Git repository (HTTPS, SSH)
  • Metrics export to Prometheus.
  • Prebuild binaries for all major OSes.
  • Ubuntu snappy packaging for Raspberry Pi and other IoT devices.

Downloads

OS Arch Link
Linux amd64 curl -O -L https://github.com/jeremyje/gowebserver/releases/download/v1.10.0/server-amd64
Linux arm curl -O -L https://github.com/jeremyje/gowebserver/releases/download/v1.10.0/server-arm
Linux arm64 curl -O -L https://github.com/jeremyje/gowebserver/releases/download/v1.10.0/server-arm64
Linux 386 curl -O -L https://github.com/jeremyje/gowebserver/releases/download/v1.10.0/server-386
Windows amd64 curl -O -L https://github.com/jeremyje/gowebserver/releases/download/v1.10.0/server-amd64.exe
Windows 386 curl -O -L https://github.com/jeremyje/gowebserver/releases/download/v1.10.0/server-386.exe
macOS amd64 curl -O -L https://github.com/jeremyje/gowebserver/releases/download/v1.10.0/server-amd64-darwin

Build

Status: Build Status Go Report Card GoDoc Snap Status codebeat badge codecov

Install Go 1.17 or newer.

git clone [email protected]:jeremyje/gowebserver.git
make

Test

make test
make bench

Sample

Sample code for embedding a HTTP/HTTPS server in your application.

import (
	"github.com/jeremyje/gowebserver/server"
	"github.com/jeremyje/gowebserver/cert"
)
func main() {
	certBuilder := cert.NewCertificateBuilder().
		SetRsa2048().
		SetValidDurationInDays(365)
	checkError(certBuilder.WriteCertificate("public.cert"))
	checkError(certBuilder.WritePrivateKey("private.key"))

	httpServer := server.NewWebServer().
		SetPorts(80, 443).
		SetMetricsEnabled(true).
		SetServePath("/", "/metrics").
		SetCertificateFile("public.cert").
		SetPrivateKey("private.key").
		SetVerbose(true)
	checkError(httpServer.SetPath("."))
	checkError(httpServer.SetUpload("./upload", "/upload.html"))
	httpServer.Serve()
}

func checkError(err error) {
	if err != nil {
		log.Fatal(err)
	}
}

Directories

Path Synopsis
cmd
Package embedded holds the embedded data.
Package embedded holds the embedded data.

Jump to

Keyboard shortcuts

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