go-chi-example-part-2

module
v0.0.0-...-f356f3c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2024 License: MIT

README


Love my work? Drop me a coffee here. :)

Platforms license

Code of Conduct Support Contribution


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 mfardiansyah.id@gmail.com
LinkedIn 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 git@github.com: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:

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

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
    

Directories

Path Synopsis
cmd
api
Package docs Code generated by swaggo/swag.
Package docs Code generated by swaggo/swag.
internal
router
Package router provides the base configurations to build a router.
Package router provides the base configurations to build a router.
pkg
authenticator
Package authenticator provides functions to authenticate incoming requests
Package authenticator provides functions to authenticate incoming requests
jwtauth
Package jwtauth provides the function for JWT Auth it hosts the old version of github.com/go-chi/jwtauth/v5 (v5.0.2) TODO: needs to update into the latest version instead of this old version
Package jwtauth provides the function for JWT Auth it hosts the old version of github.com/go-chi/jwtauth/v5 (v5.0.2) TODO: needs to update into the latest version instead of this old version
logger
Package logger provides functions to set up a new logger
Package logger provides functions to set up a new logger

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL