-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
50 lines (38 loc) · 777 Bytes
/
main.go
File metadata and controls
50 lines (38 loc) · 777 Bytes
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
package main
import (
"context"
"fmt"
"os"
"os/signal"
"strconv"
"github.com/labstack/echo/v4"
)
func main() {
var port uint64 = 3006
var err error
args := os.Args[1:]
if len(args) != 0 {
port, err = strconv.ParseUint(args[0], 10, 0)
if err != nil || port < 2 {
fmt.Println("Invalid port specified")
os.Exit(1)
}
}
address := ":" + strconv.FormatUint(port, 10)
e := echo.New()
e.HideBanner = true
e.Static("/", "web")
e.GET("/r/*", getSubreddit)
go func() {
e.Logger.Fatal(e.Start(address))
}()
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt)
<-quit
if err = e.Shutdown(context.Background()); err != nil {
e.Logger.Fatal(err)
}
}
func getSubreddit(c echo.Context) error {
return c.File("web/reddit.html")
}