This repository contains a sample Golang web application project that serves as a starting point for building your own web applications.
- Basic HTTP server listening on port 8080 with
Status
andEcho
handlers, which provide a solid starting point for implementing custom handlers that receive and return JSON data. /status
endpoint for health checks:- A simple example of a handler that returns JSON data, which can be used as a starting point for creating more complex handlers that receive and return JSON.
/echo
endpoint for echoing request messages:- Demonstrates how to read JSON data from a request and return it in the response. This can be adapted for more advanced use cases where processing or modification of the data is needed.
- Golang installed on your system
- Docker installed on your system
- Clone the repository:
git clone https://github.com/yourusername/golang-webapp-starter.git
- Change directory to the project folder:
cd golang-webapp-starter
- Build the project:
make build run
or
go build
- Run the server:
make run
or
./server
The server will start listening on port 8080.
--config
or-c
: Specify the path to the configuration file (default is$HOME/.server.yaml
)--webroot
or-w
: Define the web root folder (default is./web/dist
)
-
/status
: Health check endpoint. Returns a JSON object with astatus
key and the value "Ok". -
/echo
: Accepts a JSON object with amessage
key and echoes the request message. Logs the entire request and the message.
Execute()
: Executes the root command and initializes the server.initConfig()
: Reads the configuration file and environment variables.
Status()
: HTTP handler for the/status
endpoint. Returns the health check status.Echo()
: HTTP handler for the/echo
endpoint. Returns the echoed message from the request.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.