ws

package module
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2016 License: BSD-3-Clause Imports: 14 Imported by: 0

README

Go Report Card License

ws

A nimble web server

ws is a prototyping platform for websites.

ws started as a nimble static content web server.
It supports an init option which generates a project directory structure, creates self signed SSL keys and displays suggested environment variables for use with ws. If the directory structure already exists it will display the suggest setup.

Requirements

  • Golang version 1.7.1 or better

Setup

ws is "go gettable"

    go get github.com/rsdoiel/ws/...
compiling from source

Here's my basic approach to get things setup. I assume you've got Golang already installed.

  • ws a nimple webserver for static content
    • Built on Golangs native http/https modules
    • Restricted file service, only from the docroot and no "dot files" are served
    • No dynamic content support
    • Quick startup, everything logged to console for easy debugging or piping to a log processor
  git clone https://github.com/rsdoiel/ws $HOME/src/github.com/rsdoiel/ws
  cd $HOME/src/github.com/rsdoiel/ws
  go test
  go build
  go build cmds/ws/ws.go

If everything compiles fine then I do something like this--

  go install cmds/ws/ws.go
Compiled versions

You can also grab one of the precompiled version at https://github.com/rsdoiel/ws/releases/latest

features

  • http/https protocols
  • static file server
  • a project setup option called init

ws init takes three actions

  • create a basic site directory structure (e.g. htdocs, etc) if needed
  • creates self signed SSL certificates (e.g. etc/site.key, etc/site.pem) if appropriate
  • suggests environment variable settings (e.g like you might put in etc/setup.conf)

Configuration

Configuration for ws can be passed directly from environment variables. That makes them container friendly. The environment can be overwritten by command line options.

The standard set of environment variables are

  • WS_URL the URL to listen for by ws
  • WS_DOCROOT the directory of your static content you need to serve
    • the default is . (your current directory)
  • WS_SSL_KEY the path the the SSL key file (e.g. etc/ssl/site.key)
    • default is empty, only checked if your WS_URL is starts with https://
  • WS_SSL_CERT the path the the SSL cert file (e.g. etc/ssl/site.crt)
    • default is empty, only checked if your WS_URL is starts with https://
command line options
  • -u, -url overrides WS_URL
  • -d, -docs overrides WS_HTDOCS
  • -k, -key overrides WS_SSL_KEY
  • -c, -cert overrides WS_SSL_CERT
  • -i, -init triggers the initialization process
  • -h, -help displays the help documentation
  • -v, -version display the version of the command
  • -l, -license display software license

Documentation

Overview

Package ws provides the core library used by cmds/ws/ws.go, cmds/wsinit/wsinit.go and cmds/wsindexer/wsindexer.go

Copyright (c) 2014 - 2016, R. S. Doiel All rights not granted herein are expressly reserved by R. S. Doiel.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Index

Constants

View Source
const (
	// Version is used as a release number number for ws, wsinit, wsindexer
	Version = "0.0.8"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Configuration

type Configuration struct {
	URL     *url.URL
	DocRoot string
	SSLKey  string
	SSLCert string
}

Configuration provides the basic settings used by _ws_ and _wsint_ commands.

func (*Configuration) GenerateKeyAndCert

func (config *Configuration) GenerateKeyAndCert() error

GenerateKeyAndCert will generate a new SSL Key/Cert pair if none exist. It will return a error if they already exist.

func (*Configuration) Getenv

func (config *Configuration) Getenv() error

Getenv scans the environment variables and updates the fields in the configuration. If there is a problem parsing WS_URL then an error is returned.

func (*Configuration) InitializeProject

func (config *Configuration) InitializeProject() (string, error)

InitializeProject scans the current working path and identifies what directories need to be created, creates them, adds SSL keys/certs if needed and returns a suggested configuration file.

func (*Configuration) SetDefaults added in v0.0.8

func (config *Configuration) SetDefaults()

SetDefaults sets the structure to common default values + DocRoot = "." + URL = http://localhost:8000

func (*Configuration) String

func (config *Configuration) String() string

String returns a multiline block of text suitable to save in a text file.

func (*Configuration) Validate

func (config *Configuration) Validate() error

Validate performs a sanity check of the values in the configuration Returns nil if OK otherwise returns error

Directories

Path Synopsis
cmds
ws
ws.go - A simple web server for static files and limit server side JavaScript @author R. S. Doiel, <rsdoiel@gmail.com> Copyright (c) 2014 - 2016, R. S. Doiel All rights not granted herein are expressly reserved by R. S. Doiel.
ws.go - A simple web server for static files and limit server side JavaScript @author R. S. Doiel, <rsdoiel@gmail.com> Copyright (c) 2014 - 2016, R. S. Doiel All rights not granted herein are expressly reserved by R. S. Doiel.

Jump to

Keyboard shortcuts

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