Files
go-socket/main.go
T
gitGnome c85c66e43a add dynamic profile update, connection helper, file download metadata
- replace UserSetColor/UserSetPronouns with single UserUpdateProfile that dynamically builds one UPDATE query from UserProfileUpdateList
- add getConnectionWithResponseOnFail helper to deduplicate connection ID parsing and validation across handlers
- rename file.go to attachmentFile.go and update handler names
- GetDownloadUrlAndMetadata now fetches object metadata via StatObject and returns it alongside the presigned URL
- file download endpoint returns JSON with url and originalName
- add description field to user and DB schema
- remove unused ConnectionState variants (GroupFellow, GroupFriend)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-17 13:28:27 +02:00

52 lines
1.8 KiB
Go

package main
import (
"context"
"log"
"net/http"
"go-socket/packages/httpRequest"
"go-socket/packages/minio"
"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", "*")
w.Header().Set("Access-Control-Allow-Headers", "token, Content-Type")
if r.Method == http.MethodOptions {
w.WriteHeader(http.StatusNoContent)
return
}
h(w, r)
}
}
func main() {
ctx := context.Background()
postgresql.Init(ctx)
minio.Init(ctx)
http.HandleFunc("/new/user", withCORS(httpRequest.HandleUserNew))
http.HandleFunc("/new/connection", withCORS(httpRequest.HandleUserNewConnection))
http.HandleFunc("/new/token", withCORS(httpRequest.HandleUserNewToken))
http.HandleFunc("/new/file", withCORS(httpRequest.HandleAttachmentFileUpload))
http.HandleFunc("/mod/user/appearence", withCORS(httpRequest.HandleUserModifyAppearance))
http.HandleFunc("/mod/user/about", withCORS(httpRequest.HandleUserModProfile))
http.HandleFunc("/mod/connection/accept", withCORS(httpRequest.HandleUserElevateConnection))
http.HandleFunc("/get/connections", withCORS(httpRequest.HandleUserGetConnections))
http.HandleFunc("/get/connection/messages", withCORS(httpRequest.HandleUserGetConnectionMessages))
http.HandleFunc("/get/file", withCORS(httpRequest.HandleAttachmentFileDownload))
http.HandleFunc("/del/user", withCORS(httpRequest.HandleUserDelete))
http.HandleFunc("/del/connection", withCORS(httpRequest.HandleUserDeleteConnection))
http.HandleFunc("/msg/user", withCORS(httpRequest.HandleDm))
http.HandleFunc("/ws", wsServer.ServeWsConnection)
log.Println("listening on :8080")
log.Fatal(http.ListenAndServe(":8080", nil))
}