This is a simple Go application that exposes an HTTP API endpoint to greet users.
- A
/hello
endpoint that returns a greeting. - Accepts an optional
name
query parameter to personalize the greeting. - Includes unit tests.
- Provides a Dev Container configuration for a consistent development environment.
- Go (version 1.24 or later recommended - see
.devcontainer/go-api/devcontainer.json
for the specific version used in the dev container) - (Optional) Docker and VS Code with the Dev Containers extension to use the provided development environment.
-
Clone the repository (if you haven't already):
git clone <your-repository-url> cd <your-repository-directory>/go-api
-
Run the application:
go run main.go
The API will start, typically listening on a port like
8080
(you might need to adjust theREADME
if yourmain.go
specifies a different port).
To run the unit tests:
go test -v ./...
- Make sure you have Docker installed and running.
- Install the Dev Containers extension in VS Code.
- Open the
root
folder of the repository (the one containing.devcontainer
) in VS Code. - VS Code should prompt you to "Reopen in Container". Click it.
- VS Code will build the container image and start the development environment inside it.
- Once the container is running, you can use the integrated terminal in VS Code to run the commands mentioned above (
go run main.go
,go test -v ./...
).
The API exposes one main endpoint:
-
GET /hello
: Returns a default greeting.- Example:
curl http://localhost:8080/hello
- Response:
Hello, world!
- Example:
-
GET /hello?name=<your_name>
: Returns a personalized greeting.- Example:
curl http://localhost:8080/hello?name=DevOps
- Response:
Hello, DevOps!
- Example:
(Note: Replace
localhost:8080
with the actual host and port if it differs)
Feel free to adjust the port number, Go version details, or add more specific instructions based on your main.go
file and project setup.
Contributions are welcome! Please follow these steps:
- Fork the repository on GitHub.
- Clone your forked repository locally.
- Create a new branch for your feature or bug fix (
git checkout -b my-new-feature
). - Make your changes and commit them (
git commit -am '[feat](scope): add some feature'
). - Ensure all tests pass (
go test
). - Push your changes to your fork (
git push origin my-new-feature
). - Create a Pull Request on the original repository.
Please ensure your code follows Go best practices and includes tests for new functionality.
This project is under the MIT license. See the LICENSE for more details.
Made with ❤️ by Diego Mais 👋.