solrac97gr / go-jwt-auth Goto Github PK
View Code? Open in Web Editor NEWTemplate create for use as CookieCutter for my Golang projects, I decided to create a template with everything already working. π
Template create for use as CookieCutter for my Golang projects, I decided to create a template with everything already working. π
Line 23 in f52fb4a
golang/mock is no longer maintained -- https://github.com/golang/mock/
Maybe it is time to update the template using the maintained fork instead?
BTW, landed here from your helpful blog. Thanks a lot for all your helpful blogs.
When testing the API from swagger, I always get "Failed to fetch" error.
Doing it on CLI is fine though.
The reason that I'm reporting here is that, I'm also trying another template -- https://github.com/create-go-app/fiber-go-template/, which seems to be doing no difference than what you're doing regarding CORS:
package middleware
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/logger"
)
// FiberMiddleware provide Fiber's built-in middlewares.
// See: https://docs.gofiber.io/api/middleware
func FiberMiddleware(a *fiber.App) {
a.Use(
// Add CORS to each route.
cors.New(),
// Add simple logger.
logger.New(),
)
}
Yet, its CORS/swagger is working just fine:
What could possibly cause the difference?
How can I make the swagger work out of the box please?
Lines 60 to 73 in f52fb4a
Define your interfaces inside the
repository.go
,handlers.go
andapplication.go
file.
Hi, I don't quite get where exactly the above interfaces code should be put -- it should be put in only one of the above three files, not all of them right? If so, which one then?
Hi,
I am learning Golang, and I am reading through your repo. It is really helpful to read the code for learning, however, I see something that would make it difficult to change later on. letΒ΄s pretend I want to start a project using Postgres, and then I see this file:
`package repositories
import (
"context"
"github.com/solrac97gr/go-jwt-auth/internal/user/domain/models"
)
func (repo *UserMongoDB) Save(user *models.User) error {
_, err := repo.collection.InsertOne(context.Background(), user)
if err != nil {
repo.logger.Error("Error saving user", err)
return err
}
return nil
}`
I am not sure how would I switch from mongoDB to Postgres easily.
thanks for your time.
No response
As per The Repository Pattern
Keeping logic of your application along with your database logic makes your application much more complex, hard to test, and maintain.
There is already a proven and simple pattern that solves these issues. The pattern that allows you to separate your application logic from database logic. It allows you to make your code simpler and easier to add new functionalities.
This is not just another article with random code snippets.
This post is part of a bigger series where we show how to build Go applications that are easy to develop, maintain, and fun to work with in the long term. We are doing it by sharing proven techniques based on many experiments we did with teams we lead and scientific research.
So it is better to move the database logic out of repositories
layer into adapters, like in the trainer example.
No response
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.