Files
go-socket/main.go
T
2026-04-15 14:18:22 +02:00

43 lines
1.3 KiB
Go

package main
import (
"context"
"log"
"net/http"
http2 "go-socket/packages/http"
"go-socket/packages/postgresql"
"go-socket/packages/wsServer"
)
func withCORS(h http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
h(w, r)
}
}
func main() {
ctx := context.Background()
postgresql.Init(ctx)
http.HandleFunc("/new/user", withCORS(http2.HandleUserNew))
http.HandleFunc("/new/connection", withCORS(http2.HandleUserNewConnection))
http.HandleFunc("/new/token", withCORS(http2.HandleUserNewToken))
http.HandleFunc("/mod/user/appearence", withCORS(http2.HandleUserModifyAppearance))
http.HandleFunc("/mod/user/about", withCORS(http2.HandleUserModifyAbout))
http.HandleFunc("/mod/connection/accept", withCORS(http2.HandleUserElevateConnection))
http.HandleFunc("/get/connections", withCORS(http2.HandleUserGetConnections))
http.HandleFunc("/get/connection/messages", withCORS(http2.HandleUserGetConnectionMessages))
http.HandleFunc("/del/user", withCORS(http2.HandleUserDelete))
http.HandleFunc("/del/connection", withCORS(http2.HandleUserDeleteConnection))
http.HandleFunc("/msg/user", withCORS(http2.HandleDm))
http.HandleFunc("/ws", wsServer.ServeWsConnection)
log.Println("listening on :8080")
log.Fatal(http.ListenAndServe(":8080", nil))
}