simplesrv

command module
v0.0.0-...-e4dcdf7 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: MIT Imports: 4 Imported by: 0

README

simplesrv

simplesrv is a Go project template for a bare-bones HTTP server, with a basic layered architecture, a backing database (SQLite) and basic unit tests in a few places - not comprehensive, but enough to get things going when starting up a new templated project.

Building and running simplesrv

The run.sh Bash script takes the place of excessive Makefiles. To build:

$ ./run.sh build

which results in the simplesrv binary being built into the bin/ directory.

$ ./run.sh run

will run the server, by default on port 8080 and using an SQL database file called app.db.

For a list of tasks in the Run script, run:

$ ./run.sh help

Note the only third-party dependency is golangci-lint for the lint task.

Using as a project template

  1. Install gonew:

    $ go install golang.org/x/tools/cmd/gonew@latest
    

    (see here for more information)

  2. Then checkout simplesrv as a new templated project by:

    $ gonew github.com/chriswalker/simplesrv example/mysrv
    $ cd ./mysrv
    # aaaand work away
    

Documentation

Overview

simplesrv is a Go project template that provides a basic HTTP server backing onto a simple database (in this case an in-process SQLite). It provides enough structure for larger projects, including basic handlers, a service and simple calls to the database.

Usage:

simplesrv --sqlitedb ./app.db

Flags:

-a, --addr
    Address/port for the server to listen on.
--sqlitedb
    Path to the SQLite database file. It will be created if it does not exist.

Directories

Path Synopsis
Package db handles all database operations (currently against SQLite).
Package db handles all database operations (currently against SQLite).
Package service contains the primary business logic for the server.
Package service contains the primary business logic for the server.
Package web contains the main application server, which handles the server routes, handlers and associated HTML templates.
Package web contains the main application server, which handles the server routes, handlers and associated HTML templates.

Jump to

Keyboard shortcuts

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