Move server to sub-folder
This commit is contained in:
parent
37efde7281
commit
f2d1de9b31
|
|
@ -0,0 +1,17 @@
|
|||
package services
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
type AuthService struct {
|
||||
ctx *Context
|
||||
}
|
||||
|
||||
func (s *AuthService) FromContext(ctx *gin.Context) (*User, error) {
|
||||
session, err := s.ctx.Services.Sessions.FromContext(ctx)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return s.ctx.Services.Users.GetById(session.UserId)
|
||||
}
|
||||
|
|
@ -9,6 +9,9 @@ type Services struct {
|
|||
SensorConfig *SensorConfigService
|
||||
SensorValues *SensorValuesService
|
||||
Sensors *SensorsService
|
||||
Sessions *SessionsService
|
||||
Users *UsersService
|
||||
Auth *AuthService
|
||||
}
|
||||
|
||||
type Context struct {
|
||||
|
|
@ -25,6 +28,9 @@ func InitializeServices(ctx *Context) *Services {
|
|||
services.SensorConfig = &SensorConfigService{ctx: ctx}
|
||||
services.SensorValues = &SensorValuesService{ctx: ctx}
|
||||
services.Sensors = &SensorsService{ctx: ctx}
|
||||
services.Sessions = &SessionsService{ctx: ctx}
|
||||
services.Auth = &AuthService{ctx: ctx}
|
||||
services.Users = &UsersService{ctx: ctx}
|
||||
|
||||
return &services
|
||||
}
|
||||
Loading…
Reference in New Issue