-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
50 lines (42 loc) · 979 Bytes
/
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
package main
import "github.com/mitchellh/go-finger"
import (
"fmt"
"bufio"
"os"
"io/ioutil"
"io"
"context"
)
func main() {
profile_folder := "profiles/"
go finger.Serve(finger.HandlerFunc(func(ctx context.Context, w io.Writer, q *finger.Query) {
text := ""
filename := ""
if q.Username == "" {
filename = "root"
} else {
filename = profile_folder + q.Username
}
file, err := os.Open(filename)
if err != nil {
text = "ERR:\nNo such user!"
}
defer func() {
if err = file.Close(); err != nil {
}
}()
if err == nil {
b, err := ioutil.ReadAll(file)
if err != nil {
text = "ERR:\nNo such user!"
} else {
text = "OK:\n" + string(b)
}
}
w.Write([]byte(fmt.Sprintln(text)))
fmt.Printf("Requested username: %s\n", q.Username)
}))
fmt.Print("Flick Finger Server is running on 0.0.0.0\n")
bufio.NewReader(os.Stdin).ReadBytes('\n')
}