modified: Dockerfile
new file: bin/api_yal new file: cmd/main.go new file: go.mod new file: internal/handlers/auth.go new file: internal/server/server.go add server, files, dockerfile, build
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
FROM golang:1.25.1-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Устанавливаем зависимости для компиляции
|
||||
RUN apk add --no-cache gcc musl-dev
|
||||
|
||||
# Копируем go.mod и go.sum
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
# Копируем исходный код
|
||||
COPY . .
|
||||
|
||||
# Компилируем БЕЗ CGO (указываем путь к main.go)
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -o bin/main ./cmd/main.go
|
||||
|
||||
EXPOSE 8787
|
||||
|
||||
CMD ["./bin/main"]
|
||||
Binary file not shown.
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"api_yal/internal/handlers"
|
||||
"api_yal/internal/server"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Создаем маршрутизатор
|
||||
mux := http.NewServeMux()
|
||||
|
||||
// Регистрируем обработчики
|
||||
handlers.RegisterAuthRoutes(mux)
|
||||
|
||||
// Создаем и запускаем сервер
|
||||
srv := server.NewServer(":8787", mux)
|
||||
|
||||
log.Printf("Server starting on port %s", ":8787")
|
||||
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
||||
log.Fatalf("Server failed to start: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module api_yal
|
||||
|
||||
go 1.22.5
|
||||
@@ -0,0 +1,31 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// AuthHandler обработчик для аутентификации
|
||||
type AuthHandler struct{}
|
||||
|
||||
// NewAuthHandler создает новый экземпляр AuthHandler
|
||||
func NewAuthHandler() *AuthHandler {
|
||||
return &AuthHandler{}
|
||||
}
|
||||
|
||||
// HandleAuth обрабатывает GET запросы на /auth
|
||||
func (h *AuthHandler) HandleAuth(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
// Возвращаем статус 200 OK
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte("OK"))
|
||||
}
|
||||
|
||||
// RegisterAuthRoutes регистрирует маршруты для аутентификации
|
||||
func RegisterAuthRoutes(mux *http.ServeMux) {
|
||||
authHandler := NewAuthHandler()
|
||||
mux.HandleFunc("/auth", authHandler.HandleAuth)
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// NewServer создает новый HTTP сервер
|
||||
func NewServer(addr string, handler http.Handler) *http.Server {
|
||||
return &http.Server{
|
||||
Addr: addr,
|
||||
Handler: handler,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user