-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
56 lines (52 loc) · 1.61 KB
/
main.go
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
56
/**
*
* @author inori
* @create 2019-04-12 15:03
*/
package main
import (
"flag"
"fmt"
"github.com/gin-gonic/gin"
"net/http"
"time"
"web-terminal/internal"
)
func main() {
var port string
flag.StringVar(&port, "port", "8080", "the server port!")
fmt.Println(port)
engine := gin.Default()
//engine.StaticFS("/swagger", http.Dir("swagger"))
engine.Static("/static", "./static")
initRouter(engine)
var readTimeOut time.Duration = 10000000000000
var writeTimeOut time.Duration = 10000000000000
s := &http.Server{
Addr: ":"+port,
Handler: engine,
ReadTimeout: readTimeOut * time.Second,
WriteTimeout: writeTimeOut * time.Second,
MaxHeaderBytes: 1 << 20,
}
// service connections
if err := s.ListenAndServe(); err != nil && err != http.ErrServerClosed {
panic(err)
}
}
func initRouter(engine *gin.Engine) {
engine.GET("/hello", internal.HelloWord)
engine.POST("/v1/terminal", internal.HandleExecNodeShell)
engine.GET("/v1/sockjs/*any", func(context *gin.Context) {
handler := internal.CreateAttachHandler("/v1/sockjs")
handler.ServeHTTP(context.Writer, context.Request)
})
engine.POST("/v1/sockjs/*any", func(context *gin.Context) {
handler := internal.CreateAttachHandler("/v1/sockjs")
handler.ServeHTTP(context.Writer, context.Request)
})
engine.OPTIONS("/v1/sockjs/*any", func(context *gin.Context) {
handler := internal.CreateAttachHandler("/v1/sockjs")
handler.ServeHTTP(context.Writer, context.Request)
})
}