-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjaf.go
62 lines (48 loc) · 1.19 KB
/
jaf.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
53
54
55
56
57
58
59
60
61
62
package main
import (
"flag"
"fmt"
"log"
"math/rand"
"net/http"
"time"
"github.com/leon-richardt/jaf/exifscrubber"
)
const allowedChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
var config Config
type parameters struct {
configFile string
}
func parseParams() *parameters {
configFile := flag.String("configFile", "jaf.conf", "path to config file")
flag.Parse()
retval := ¶meters{}
retval.configFile = *configFile
return retval
}
func main() {
rand.Seed(time.Now().UnixNano())
log.SetPrefix("jaf > ")
params := parseParams()
// Read config
config, err := ConfigFromFile(params.configFile)
if err != nil {
log.Fatalf("could not parse config file: %s\n", err.Error())
}
handler := uploadHandler{
config: config,
}
if config.ScrubExif {
scrubber := exifscrubber.NewExifScrubber(config.ExifAllowedIds, config.ExifAllowedPaths)
handler.exifScrubber = &scrubber
}
// Start server
uploadServer := &http.Server{
ReadTimeout: 30 * time.Second,
WriteTimeout: 30 * time.Second,
Addr: fmt.Sprintf(":%d", config.Port),
}
log.Printf("starting jaf on port %d\n", config.Port)
http.Handle("/upload", &handler)
uploadServer.ListenAndServe()
}