goweb

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2017 License: MIT Imports: 0 Imported by: 0

README

goweb

Release Build Status Coverage GoDoc

A Go library for building tiny web applications such as dashboards, REST APIs, etc.

Features

  • Standard library compatible
  • Listening multiple ports
  • Upload file handling
  • Templating
  • Content detection
  • No external dependency
  • High code coverage

Installation

go get github.com/devfacet/goweb

Usage

A basic app

See basic for full code.

// Init the server
web := server.New(server.Options{
  ID:      "web",
  Address: "localhost:3000",
})

// Pages
pages := []page.Options{
  page.Options{
    URLPath:    "/",
    FilePath:   "/templates/index.html",
    FileSystem: &fs,
    TemplateData: PageData{
      Title:       pageTitle,
      Description: pageDesc,
      Content:     "Hello world",
    },
  },
  page.Options{
    URLPath:      "foo",
    Content:      "{{.Body}}",
    TemplateData: struct{ Body string }{Body: "foo"},
  },
  page.Options{
    URLPath:      "bar/",
    Content:      "{{.Body}}",
    MatchAll:     true,
    TemplateData: struct{ Body string }{Body: "bar"},
  },
}

for _, v := range pages {
  p, err := page.New(v)
  if err != nil {
    log.Logger.Fatal(err)
  }
  if err := web.AddPage(p); err != nil {
    log.Logger.Fatal(err)
  }
}

// Listen
if err := web.Listen(); err != nil {
  log.Logger.Fatal(err)
}
cd examples/basic/
go build .
./basic

Build

go build .

Test

./test.sh

Release

git add CHANGELOG.md # update CHANGELOG.md
./release.sh v1.0.0  # replace "v1.0.0" with new version

git ls-remote --tags # check the new tag

Contributing

  • Code contributions must be through pull requests
  • Run tests, linting and formatting before a pull request (test.sh)
  • Pull requests can not be merged without being reviewed
  • Use "Issues" for bug reports, feature requests and discussions
  • Do not refactor existing code without a discussion
  • Do not add a new third party dependency without a discussion
  • Use semantic versioning and git tags for versioning

License

Licensed under The MIT License (MIT)
For the full copyright and license information, please view the LICENSE.txt file.

Documentation

Overview

Package goweb is a library for building web applications.

Directories

Path Synopsis
Package content provides functions for content handling such as content type detection.
Package content provides functions for content handling such as content type detection.
examples
basic command
A basic web app
A basic web app
Package log implements a simple logging package Currently it's pretty much a place holder for future implementations.
Package log implements a simple logging package Currently it's pretty much a place holder for future implementations.
Package page provides functions for handling web pages
Package page provides functions for handling web pages
Package request provides functions for handling HTTP requests
Package request provides functions for handling HTTP requests
Package route provides functions for HTTP routes
Package route provides functions for HTTP routes
Package server implements a web server
Package server implements a web server

Jump to

Keyboard shortcuts

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