-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
41 lines (34 loc) · 884 Bytes
/
server.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
package main
import (
"errors"
"log"
"net/http"
)
// ServerCommand define the server command that responsible for serving a http server
// for ASCII image.
type ServerCommand struct {
Options
Delay float64
Host string
Port string
}
// server for ServerCommand setup a http server that can share the ASCII image to remote client
func (serverCommand *ServerCommand) Serve(args []string) error {
filename := args[0]
flushHandler, supported := NewFlushHandler(filename, &serverCommand.Options)
if !supported {
return errors.New("not supported file type")
}
err := flushHandler.Init()
if err != nil {
return err
}
http.HandleFunc("/tree", flushHandler.HandlerFunc())
addr := serverCommand.Host + ":" + serverCommand.Port
log.Println("Going to listen and serve on " + addr)
err = http.ListenAndServe(addr, nil)
if err != nil {
return err
}
return nil
}