about summary refs log tree commit diff
path: root/main.go
blob: 28db957dd6eda77633633c2ec27cdff1384aac67 (plain)
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
package main

import (
    "fmt"
    "net/http"
    "log"
    "github.com/goftp/server"
    filedriver "github.com/goftp/file-driver"
)

var(
    metrics_num_passwords int
)


func main() {
    log.Println("Starting FTP listener")


    go func() {

        factory := &filedriver.FileDriverFactory{
      		RootPath: "",
      		Perm:     server.NewSimplePerm("user", "group"),
        }

        opts := &server.ServerOpts{
          Factory:  factory,
          Port:     21,
          Hostname: "::",
          Auth:     &FakeAuth{Name: "", Password: ""},
          Logger:   &server.DiscardLogger{},
        }

        server := server.NewServer(opts)
        err := server.ListenAndServe()
        if err != nil {
          log.Fatal("Error starting server:", err)
        }
    }()

    log.Println("Starting HTTP metrics listener")
    http.HandleFunc("/metrics", metricsHandler)
    listenErr := http.ListenAndServe(":48081", nil) // set listen port
    if listenErr != nil {
        log.Fatalln(listenErr.Error())
    }
}

// Handle HTTP /metrics requests
func metricsHandler(w http.ResponseWriter, req *http.Request) {
    fmt.Fprintf(w, "metrics_num_passwords %d\n", metrics_num_passwords)
}