Files
go-socket/main.go
T

36 lines
1.2 KiB
Go

package main
import (
"context"
"log"
"net/http"
)
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()
DbInit(ctx)
http.HandleFunc("/new/client", withCORS(HttpHandleNewClient))
http.HandleFunc("/new/token", withCORS(HttpHandleNewToken))
http.HandleFunc("/new/group", withCORS(HttpHandeGroupCreate))
http.HandleFunc("/new/message", withCORS(HttpHandleNewMessage))
http.HandleFunc("/mod/group/addclients", withCORS(HttpHandleGroupAddClient))
http.HandleFunc("/mod/group/removeclients", withCORS(HttpHandleGroupRemoveClient))
http.HandleFunc("/mod/group/color", withCORS(HttpHandleGroupChangeColor))
http.HandleFunc("/mod/group/owner", withCORS(HttpHandleGroupChangeOwner))
http.HandleFunc("/get/groups", withCORS(HttpHandleGroupsGetWithoutMembers))
http.HandleFunc("/get/group/members", withCORS(HttpHandleGroupMembersGet))
http.HandleFunc("/del/group", withCORS(HttpHandleGroupRemove))
http.HandleFunc("/ws", ServeWsConnection)
log.Println("listening on :8080")
log.Fatal(http.ListenAndServe(":8080", nil))
}