A minimal Go RESTful web application using Bootstrap and mux.
Getting Started
-
Be sure Go is properly installed, along with a configured $GOPATH.
-
Set the environment variables GITHUB_USERNAME
and CONFIG_CF
. For development, set CONFIG_CF=config.development
and for production set CONFIG_CF=config.production
. The corresponding JSON config files can be found in /._config_files
/.
$ export GITHUB_USERNAME=<your_github_username>
$ export CONFIG_CF=config.development
- Set environment variables
username
, password
, and database
for Postgresql, and be sure to create them in postgresql as well:
$ export GOFIGURE_USERNAME=<your_postgres_username_for_database>
$ export GOFIGURE_PASSWORD=<your_password>
$ export GOFIGURE_DATABASE=<database_name>
Running
To run the application:
$ sh clean.sh
$ sh run.sh
Navigate to http://localhost:8080 and you should see the following page:
Project Structure
The main entry for the application is is main.go
, where the configuration
file is loaded, a database connection is created, and the application is started.
The server-side code is located in api/
:
$ tree api/
api/
├── app
│ ├── app.go
│ └── app_test.go
├── config
│ ├── configuration.go
│ ├── configuration_test.go
│ ├── database.go
│ ├── directory.go
│ ├── log.go
│ └── server.go
├── handler
│ ├── handlers.go
│ └── handlers_test.go
└── model
├── database.go
├── database_test.go
├── message.go
└── model.go
There is built in support for creating api endpoints:
// ./api/app/app.go
func (a *App) initializeRoutes(routeConfig *cfg.Configuration) {
// Initialize config for handler
handler.Initialize(routeConfig)
// API Endpoints
// Register your API endpoints here. E.g.:
// api := a.Router.PathPrefix("/api/v1").Subrouter() <-- create appropriate
// path prefix for Subrouter
// api.Methods("GET").Path("/<dir>").HandlerFunc(<your_handler>)
api := a.Router.PathPrefix("/api/v1").Subrouter()
api.Methods("GET").Path("/greetings/hello/{name}").HandlerFunc(handler.GetHelloHandler)
All client-side code is located in the static/
directory:
$ tree static
static
├── css
│ └── main.css
├── img
│ └── index.png
├── index.html
├── js
└── vendor
└── bootstrap-4.0.0