Инициализация проекта + первые наработки
This commit is contained in:
27
internal/AuthServer.go
Normal file
27
internal/AuthServer.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
httpServer *http.Server
|
||||
}
|
||||
|
||||
func (s *Server) Run(port string,handler http.Handler) error {
|
||||
s.httpServer = &http.Server{
|
||||
Addr: ":" + port,
|
||||
Handler: handler,
|
||||
ReadTimeout: 10 * time.Second,
|
||||
WriteTimeout: 10 * time.Second,
|
||||
MaxHeaderBytes: 1 << 20,
|
||||
}
|
||||
return s.httpServer.ListenAndServe()
|
||||
}
|
||||
|
||||
func (s *Server) Shutdown(ctx context.Context) error{
|
||||
return s.httpServer.Shutdown(ctx)
|
||||
}
|
||||
|
||||
37
internal/Dtos.go
Normal file
37
internal/Dtos.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package internal
|
||||
|
||||
type RegistrationUser struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
const (
|
||||
Student UserRole = iota
|
||||
Teacher
|
||||
Admin
|
||||
)
|
||||
|
||||
type User struct {
|
||||
Username string
|
||||
Password string
|
||||
UserRole UserRole
|
||||
}
|
||||
|
||||
func (user *User) ChangeRole(userRole UserRole) {
|
||||
user.UserRole = userRole
|
||||
}
|
||||
|
||||
type UserRole int
|
||||
|
||||
func (role UserRole) String() string {
|
||||
switch role {
|
||||
case Student:
|
||||
return "student"
|
||||
case Teacher:
|
||||
return "teacher"
|
||||
case Admin:
|
||||
return "admin"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
}
|
||||
13
internal/handler/auth.go
Normal file
13
internal/handler/auth.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func (h *Handler) signUp(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func (h *Handler) signIn(c *gin.Context) {
|
||||
|
||||
}
|
||||
17
internal/handler/handler.go
Normal file
17
internal/handler/handler.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package handler
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
type Handler struct {
|
||||
}
|
||||
|
||||
func (h *Handler) InitRoutes() *gin.Engine {
|
||||
router := gin.New()
|
||||
|
||||
auth := router.Group("/auth")
|
||||
{
|
||||
auth.POST("/sign-up", h.signUp)
|
||||
auth.POST("/sign-in", h.signIn)
|
||||
}
|
||||
return router
|
||||
}
|
||||
Reference in New Issue
Block a user