This is a simple API written in Go using the Gin web framework. It allows you to manage a collection of gin spirits, including retrieving all gins, adding new gins, and fetching a specific gin by its ID.
To get started with using this API, follow the instructions below:
- Go (>= 1.22.1) installed on your system. You can download and install it from golang.org.
- Git installed on your system. You can download and install it from git-scm.com.
-
Clone this repository to your local machine:
git clone https://github.com/webserverdude/go-gin-api.git
-
Change into the directory:
cd go-gin-api
-
Install dependencies:
go mod tidy
To enable HTTPS for your server, you'll need to create SSL private and public keys. Here's how to do it:
-
Open a terminal window.
-
Run the following command to generate a private key file (
server.key
):openssl genrsa -out server.key 2048
-
Run the following command to generate a certificate signing request (CSR):
openssl req -new -key server.key -out server.csr
-
Now, create a self-signed certificate using the CSR and private key:
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
This command will create a self-signed certificate (
server.crt
) valid for 365 days.
-
Run the Go server:
go run main.go
-
The API server will start running on
https://localhost:8000
. You can now make requests to the following endpoints:GET /gins
: Retrieve all gins.GET /gins/{id}
: Retrieve a specific gin by its ID.POST /gins
: Add a new gin.
-
You can use tools like cURL or Postman to interact with the API endpoints.
The API documentation is provided using an OpenAPI specification file. You download the file by navigating to https://localhost:8000/openapi.json
after starting the server.
This project is licensed under the MIT License.