Skip to content

Latest commit

 

History

History
130 lines (100 loc) · 2.82 KB

README.md

File metadata and controls

130 lines (100 loc) · 2.82 KB

goweb

Release Build Status Coverage GoDoc

A Go library for building tiny web applications such as dashboards, SPAs, 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.