Skip to content

devfacet/goweb

Repository files navigation

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.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy