forked from acheong08/ChatGPT-API-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
55 lines (43 loc) · 1.2 KB
/
main.go
File metadata and controls
55 lines (43 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
// Import local packages
"net/http"
"os"
"github.com/ChatGPT-Hackers/ChatGPT-API-server/handlers"
"github.com/ChatGPT-Hackers/ChatGPT-API-server/utils"
"github.com/gin-gonic/gin"
)
func main() {
// get arg server port and admin key
if len(os.Args) < 3 {
println("Usage: ./ChatGPT-API-server <port> <admin key>")
return
}
println(os.Args[1], os.Args[2])
// Make database
err := utils.DatabaseCreate()
if err != nil {
println("Failed to create database:", err.Error())
return
}
router := gin.Default()
//// # Headers
// Allow CORS
router.Use(func(c *gin.Context) {
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
})
//// # Add routes
// Register new client connection
router.GET("/client/register", handlers.Client_register)
router.POST("/api/ask", handlers.API_ask)
router.GET("/api/connections", handlers.API_getConnections)
router.POST("/admin/users/add", handlers.Admin_userAdd)
router.POST("/admin/users/delete", handlers.Admin_userDel)
router.GET("/admin/users", handlers.Admin_usersGet)
// Add a health endpoint
router.GET("/health", func(c *gin.Context) {
c.String(http.StatusOK, "OK")
})
// Start server
router.Run(":" + os.Args[1])
}