GithubHelp home page GithubHelp logo

found-pleiade / dionysos-server Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 225 KB

API instance for dionysos client application

License: GNU General Public License v3.0

Shell 1.02% Dockerfile 0.44% Go 98.55%
docker gin-gonic golang

dionysos-server's People

Contributors

brawdunoir avatar whitediamondz avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

u5surf

dionysos-server's Issues

Add UserUpdate type

When patching a model, any field without omitempty will be erased if not specified in the database during an UpdateDocument.
But during creation you need to have fields with binding:required.

Create middleware to centralize responses and logs

Right now, in each route, we call c.JSON and log.Printf.
It might be better to have a set of constant return codes that routes will return/set in context ; and to grab them to call set response and logger.
That way we will centralize responses formatting (like "Room not found")

Correct typo

exceptedID instead of expectedID in utils/routes/responses.go

Implement authentication and authorization on certain routes

https://stackoverflow.blog/2021/10/06/best-practices-for-authentication-and-authorization-for-rest-apis/
https://developer.mozilla.org/fr/docs/Web/HTTP/Headers/Authorization

We will be using header Authorization Basic id:password where id:password is in base64. In addition, we will use a middleware in gin to verify credentials. Continue to the route if it is okay and send 401 if not.
Need to implement WWW-Authenticate as well https://developer.mozilla.org/fr/docs/Web/HTTP/Headers/WWW-Authenticate

Run tests automatically on push

On commit :

  • Lint
  • Security checks (?)

On PR on main :

  • Build the docker
  • Push it on DockerHub
  • Auto-deploy on test server

Cache doesn't get invalidated

With tests on changing a user's name, the following GET still returns the old name and we have a stack trace in the code

api         | 2022/08/11 13:22:18 [Recovery] 2022/08/11 - 13:22:18 panic recovered:
api         | PATCH /users/3 HTTP/1.1
api         | Host: localhost:8080
api         | Accept: */*
api         | Accept-Encoding: gzip, deflate, br
api         | Authorization: *
api         | Cache-Control: no-cache
api         | Connection: keep-alive
api         | Content-Length: 31
api         | Content-Type: application/json
api         | Postman-Token: 27c919f7-b5c7-4516-a896-3d061442e07c
api         | User-Agent: PostmanRuntime/7.29.2
api         | X-Requested-With: XMLHttpRequest
api         | 
api         | 
api         | runtime error: invalid memory address or nil pointer dereference
api         | /usr/local/go/src/runtime/panic.go:220 (0x44b7d5)
api         |   panicmem: panic(memoryError)
api         | /usr/local/go/src/runtime/signal_unix.go:818 (0x44b7a5)
api         |   sigpanic: panicmem()
api         | /app/routes/router.go:141 (0xb853ca)
api         |   invalidateCacheURI: code := c.Request.Response.StatusCode
api         | /go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:173 (0xb85155)
api         |   (*Context).Next: c.handlers[c.index](c)
api         | /app/routes/router.go:113 (0xb8502f)
api         |   authentication: c.Next()
api         | /go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:173 (0x8e91e1)
api         |   (*Context).Next: c.handlers[c.index](c)
api         | /go/pkg/mod/github.com/gin-gonic/[email protected]/recovery.go:101 (0x8e91cc)
api         |   CustomRecoveryWithWriter.func1: c.Next()
api         | /go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:173 (0xb852fb)
api         |   (*Context).Next: c.handlers[c.index](c)
api         | /app/routes/router.go:133 (0xb852d3)
api         |   options: c.Next()
api         | /go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:173 (0x8e91e1)
api         |   (*Context).Next: c.handlers[c.index](c)
api         | /go/pkg/mod/github.com/gin-gonic/[email protected]/recovery.go:101 (0x8e91cc)
api         |   CustomRecoveryWithWriter.func1: c.Next()
api         | /go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:173 (0x8e82c6)
api         |   (*Context).Next: c.handlers[c.index](c)
api         | /go/pkg/mod/github.com/gin-gonic/[email protected]/logger.go:240 (0x8e82a9)
api         |   LoggerWithConfig.func1: c.Next()
api         | /go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:173 (0x8e7390)
api         |   (*Context).Next: c.handlers[c.index](c)
api         | /go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:616 (0x8e6ff8)
api         |   (*Engine).handleHTTPRequest: c.Next()
api         | /go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:572 (0x8e6b3c)
api         |   (*Engine).ServeHTTP: engine.handleHTTPRequest(c)
api         | /usr/local/go/src/net/http/server.go:2916 (0x6a1fba)
api         |   serverHandler.ServeHTTP: handler.ServeHTTP(rw, req)
api         | /usr/local/go/src/net/http/server.go:1966 (0x69cfb6)
api         |   (*conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req)
api         | /usr/local/go/src/runtime/asm_amd64.s:1571 (0x465ac0)
api         |   goexit: BYTE    $0x90   // NOP
api         | 
api         | [GIN-debug] [WARNING] Headers were already written. Wanted to override status code 204 with 500
api         | [GIN] 2022/08/11 - 13:22:18 | 500 |      5.1419ms |      172.18.0.1 | PATCH    "/users/3"

Remove base url in uri

The client has added the base path to its default url, so we should not return this on POST

Enforce best practises

  • Add default base path to /api/vX. vX is the version of the api (v1, v2, etc.)
  • Correct responses:
    • 204 for PATCH and DELETE
  • Remove trailing '/' at the end of the routes
  • Add documentation using this https://github.com/swaggo/gin-swagger on current routes:
    • CRUD user
    • CRUD room
    • /version

Correct tests

It looks like some small errors have been missed in the tests

Correct nil pointer reference on OPTIONS call

Have

runtime error: invalid memory address or nil pointer dereference

Happens on line 132 of the router.go file, c.Next() call, which seems weird.

if c.Request.Method != "OPTIONS" {
    c.Next()
} else {
    c.AbortWithStatus(http.StatusOK)
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.