https://github.com/marcoshuck/auth-go
An authentication microservice written in go.
https://github.com/marcoshuck/auth-go
Last synced: about 1 month ago
JSON representation
An authentication microservice written in go.
- Host: GitHub
- URL: https://github.com/marcoshuck/auth-go
- Owner: marcoshuck
- Created: 2020-08-29T05:44:12.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-08-29T21:26:14.000Z (over 4 years ago)
- Last Synced: 2025-02-05T06:43:52.828Z (3 months ago)
- Language: Go
- Size: 26.4 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Authentication microservice
This project is an authentication microservice written in go that follows Clean Architecture and SOLID patterns.## Installation
```bash
$ go mod download
```## Routes
This microservice has an Authentication Controller in charge of handling authentication requests using gin.| Route | Method | Input | Output |
| ----- | ------ | ----- | ------ |
| /auth/register | POST | [Register](https://github.com/marcoshuck/auth-go/blob/master/pkg/dto/register.go) | [Public User](https://github.com/marcoshuck/auth-go/blob/master/pkg/dto/user.go#L22) |
| /auth/login | POST | [Login](https://github.com/marcoshuck/auth-go/blob/master/pkg/dto/login.go) | [Access Token](https://github.com/marcoshuck/auth-go/blob/master/pkg/controller/auth_controller.go#L41) |## Usage
```go
func main() {
// Initialize router
router := http.NewRouter()// Initialize db connection
// TODO: Replace sqlite3 with MySQL/Postgres
db, err := gorm.Open("sqlite3", "file::memory:?cache=shared")
if err != nil {
panic(err)
}// Migrate models
model.Migrate(db)// Initialize validator
v := validator.NewValidator()// Initialize user layers
userRepository := repository.NewUserRepository(db)
userService := service.NewUserService(userRepository, v)// TODO: Remove this block
err = os.Setenv("APP_SECRET_KEY", "changeme")
if err != nil {
panic(err)
}// Initialize auth layers
authService := service.NewAuthService(userService, v, []byte(os.Getenv("APP_SECRET_KEY")))
authController := controller.NewAuthController(authService)// Register routes
router = http.Register(router, authController)// Run http server
err = router.Run(":3000")
if err != nil {
panic(err)
}
}
```## 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.
## TODO
- [ ] Refresh tokens
- [ ] Invalidation
- [ ] Logging
- [X] Validation
- [ ] CI/CD
- [ ] Error handling
- [ ] Event subscription/publishing
- [ ] API Rest layers tests (Controller, service, repository)
- [ ] Integration tests.