# README
Love my work? Drop me a coffee here. :)
Api Service with Swagger built with Go-Chi framework
Global Template Repository for Development and Operations Of Your Projects.
Key | Values |
---|---|
Author | Muhammad Febrian Ardiansyah |
[email protected] | |
Muhammad Febrian Ardiansyah | |
Personal Homepage | https://mfardiansyah.id |
Table of Contents
Getting Started
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
Prerequisites
What things you need to install the software and how to install them
apt-get -y install git
Or
yum -y install git
Installation
A step by step series of examples that tell you how to get a development env running
Say what the step will be clone this repository.
git clone [email protected]:ardihikaru/go-chi-example-part-2.git
Development
- N/A
Usage
Reference and programming instructional materials.
Swag Usage
-
Add comments on your API handlers using the declarative syntax explained here
-
Install swaggo/swag?
go install github.com/swaggo/swag/cmd/swag@latest
- Run the Swag in your Go project root folder which contains
main.go
file.
swag init -g cmd/main/main.go
swag init --parseDependency -g cmd/api/main.go
If your main.go
file is not in root but uses the models defined in root, you can provide the path of main.go
file.
swag init -d "./" -g "$FOLDER_NAME/main.go"
Swag will parse comments and generate required files(docs folder and docs/doc.go).
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
Looking to contribute to our code but need some help? There's a few ways to get information:
- Connect with me on Twitter
- Connect with me on Facebook
- Connect with me on LinkedIn
- Log an issue here on github
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.
Authors
- Muhammad Febrian Ardiansyah - Initial work
License
This project is licensed under the MIT License - see the LICENSE file for details
Copyright © 2024 Public Use. All Rights Reserved.
Acknowledgments
- Hat tip to anyone whose code was used
- Inspiration
- etc
MISC
- Validates CORS
curl -v --request OPTIONS 'http://localhost:8080/public/service-id' -H 'Origin: http://other-domain.com' -H 'Access-Control-Request-Method: GET'
curl -v --request OPTIONS 'http://localhost:8080/auth/login' -H 'Origin: http://other-domain.com' -H 'Access-Control-Request-Method: POST'
curl -v -X OPTIONS \
http://localhost:8080/public/service-id \
-H 'cache-control: no-cache' \
-F Origin=http://www.google.com
- Allowed CORS result (please set
cors.Debug: true
)[cors] 2024/06/16 23:53:13 Handler: Preflight request [cors] 2024/06/16 23:53:13 Preflight response headers: map[Access-Control-Allow-Methods:[GET] Access-Control-Allow-Origin:[http://other-domain.com] Access-Control-Max-Age:[6000] Vary:[Origin Access-Control-Request-Method Access-Control-Request-Headers]]
- NOT Allowed CORS result (please set
cors.Debug: true
)[cors] 2024/06/16 23:52:13 Handler: Preflight request [cors] 2024/06/16 23:52:13 Preflight aborted: origin 'http://other-domain.com' not allowed