26

syntaqx/serve: a static http server anywhere you need one

 6 years ago
source link: https://www.tuicool.com/articles/hit/Mvim22e
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

eUNjUfv.png!web

serve is a static http server anywhere you need one.

TL;DR

It's basically python -m SimpleHTTPServer 8080 written in Go, because who can remember that many letters?

Installation

serve can be installed in a handeful of ways:

Homebrew on macOS

If you are using Homebrew on macOS, you can install serve with the following command:

brew install syntaqx/tap/serve

Download the binary

Quickly download install the latest release:

curl -sfL https://install.goreleaser.com/github.com/syntaqx/serve.sh | sh

Or manually download the latest release binary for your system and architecture and install it into your $PATH .

From source

To build from source, check out the instructions on getting started with.

Usage

Run a server from the current directory:

serve

Or, specify the directory. Paths can be both relative and absolute:

serve /var/www # or serve -dir=/var/www

Development

To develop serve or interact with its source code in any meaningful way, be sure you have the following installed:

Prerequisites

You will need to activate Modules for your version of Go, generally by invoking go with the support GO111MODULE=on environment variable set.

Install

You can download and install the project from GitHub by simply running:

git clone [email protected]:syntaqx/serve.git && cd $(basename $_ .git)
make install

This will install serve into your $GOPATH/bin directory, which assuming is properly appended to your $PATH , can now be used:

$ serve version
serve version v0.0.6-8-g5074d63 windows/amd64

Using serve manually

Besides running serve using the provided binary, you can also embed a serve.FileServer into your own Go program:

package main

import (
	"log"
	"net/http"

	"github.com/syntaqx/serve"
)

func main() {
	fs := serve.NewFileServer()
	log.Fatal(http.ListenAndServe(":8080", fs))
}

License

serve is open source software released under the MIT license .


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK