gowebserver

module
v2.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 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/v2.7.0/server-amd64; chmod +x gowebserver

# Host the current directory.
./gowebserver

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

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

# Install in your Kubernetes Cluster.
kubectl apply -f https://raw.githubusercontent.com/jeremyje/gowebserver/main/install/kubernetes.yaml

Windows Service

sc.exe create gowebserver start= delayed-auto binpath= "C:\apps\gowebserver.exe -configfile=C:\apps\gowebserver.yaml"
sc.exe failure gowebserver reset= 0 actions= restart/1000
sc.exe start gowebserver

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 local or HTTP served static files from:
    • Local directory (current directory is default)
    • ZIP archive
    • Tarball archive (.tar, .tar.bz2, .tar.gz, .tar.lz4, .tar.xz)
    • 7-zip
    • RAR
    • Git repository (HTTPS, SSH)
  • Metrics export to Prometheus.
  • Prebuild binaries for all major OSes.

Downloads

OS Arch Link
Linux amd64 curl -O -L https://github.com/jeremyje/gowebserver/releases/download/v2.7.0/server-amd64
Linux arm curl -O -L https://github.com/jeremyje/gowebserver/releases/download/v2.7.0/server-arm
Linux arm64 curl -O -L https://github.com/jeremyje/gowebserver/releases/download/v2.7.0/server-arm64
Windows amd64 (New-Object System.Net.WebClient).DownloadFile("https://github.com/jeremyje/gowebserver/releases/download/v2.7.0/server-amd64.exe", "server-amd64.exe")
macOS amd64 curl -O -L https://github.com/jeremyje/gowebserver/releases/download/v2.7.0/server-amd64-darwin
macOS arm64 curl -O -L https://github.com/jeremyje/gowebserver/releases/download/v2.7.0/server-arm64-darwin

Build

example workflow Go Report Card Go Reference codebeat badge codecov Total alerts

Install Go 1.19 or newer.

# Install Dependencies for Building and Testing
sudo apt-add-repository non-free
sudo apt-get update
sudo apt-get -y -q install lz4 p7zip-full rar unrar
# Clone the Codebase
git clone git@github.com:jeremyje/gowebserver.git
# Build the Code
make -j$(nproc)

Test

make test
make bench

Sample

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

package main

import (
  "github.com/jeremyje/gowebserver/v2/pkg/gowebserver"
  "go.uber.org/zap"
)

func main() {
  logger, err := zap.NewProduction()
  if err != nil {
    zap.S().Fatal(err)
  }
  if err == nil {
    zap.ReplaceGlobals(logger)
  }
  defer logger.Sync()
  httpServer, err := gowebserver.New(&gowebserver.Config{
    Serve: []gowebserver.Serve{{Source: ".", Endpoint: "/"}},
  })
  if err != nil {
    zap.S().Fatal(err)
  }

  termCh := make(chan error)
  httpServer.Serve(termCh)
}

Directories

Path Synopsis
cmd
certtool
Package main is the entry point for certtool.
Package main is the entry point for certtool.
internal
pkg
certtool
Package certtool is the public interface for integrating with auto generating certificates.
Package certtool is the public interface for integrating with auto generating certificates.

Jump to

Keyboard shortcuts

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