-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserve.go
52 lines (29 loc) Β· 880 Bytes
/
serve.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
package main
import (
"github.com/pterm/pterm"
"github.com/valyala/fasthttp"
"time"
)
func serveWorld(name string) error {
pterm.Println()
pterm.Success.Println("------ β¨ Servidor iniciado correctamente en puerto 1000 β¨ ------")
time.Sleep(time.Second * 1)
pterm.Println()
pterm.Info.Println("... π Para cerrar el servidor pulsa Ctrl + C ...")
handler := func(ctx *fasthttp.RequestCtx) {
method := string(ctx.Method())
if method == "GET" {
ctx.Response.Header.Set("Name", name)
ctx.Response.Header.Set("Content-Type", "application/zip")
ctx.SendFile(name)
} else {
ctx.Write([]byte("Method " + method + " not allowed"))
}
}
gzipHandler := fasthttp.CompressHandlerLevel(handler, fasthttp.CompressBestCompression)
error := fasthttp.ListenAndServe(":1000", gzipHandler)
if error != nil {
return error
}
return nil
}