In order to mitigate against the brute force attacks against Gitlab accounts, we are moving to all edu-ID Logins. We would like to remind you to link your account with your edu-id. Login will be possible only by edu-ID after December 31, 2021. Here you can find the instructions for linking your account.

If you don't have a SWITCH edu-ID, you can create one with this guide here

kind regards

main.go 1.85 KB
Newer Older
Jürgen Enge's avatar
Jürgen Enge committed
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main

import (
	"encoding/json"
	"flag"
	"fmt"
	"gitlab.switch.ch/memoriav/memobase-2020/services/histogram/pkg/histogram"
	"gitlab.switch.ch/memoriav/memobase-2020/services/histogram/pkg/service"
	"io"
	"log"
	"os"
	"path/filepath"
)

func main() {
	configFile := flag.String("cfg", "./histogram.toml", "config file location")
	imgFile := flag.String("img", "", "config file location")
	flag.Parse()

	var exPath = ""
	// if configfile not found try path of executable as prefix
	if !service.FileExists(*configFile) {
		ex, err := os.Executable()
		if err != nil {
			panic(err)
		}
		exPath = filepath.Dir(ex)
		if service.FileExists(filepath.Join(exPath, *configFile)) {
			*configFile = filepath.Join(exPath, *configFile)
		} else {
			log.Fatalf("cannot find configuration file: %v", *configFile)
			return
		}
	}
	// configfile should exists at this place
	var config Config
	config = LoadConfig(*configFile)

	// create logger instance
	log, lf := service.CreateLogger("indexer", config.Logfile, config.Loglevel)
	defer lf.Close()

	var accesslog io.Writer
	if config.AccessLog == "" {
		accesslog = os.Stdout
	} else {
		f, err := os.OpenFile(config.AccessLog, os.O_WRONLY|os.O_CREATE, 0755)
		if err != nil {
			log.Panicf("cannot open file %s: %v", config.AccessLog, err)
			return
		}
		defer f.Close()
		accesslog = f
	}
	fmt.Sprintf("%v", accesslog)

	hist, err := histogram.NewHistogram(
		config.ImageMagick.Convert,
		config.ImageMagick.Resize,
		config.ImageMagick.Remap,
		config.Colormap,
		config.ImageMagick.Colors,
		config.ImageMagick.Timeout.Duration,
		config.ImageMagick.Wsl)

	// if necessary create a colormap image
	result, err := hist.Exec(*imgFile)
	if err != nil {
		log.Panicf("error getting histogram: %v", err)
		return
	}

	json, err := json.Marshal(result)
	if err != nil {
		log.Errorf("cannot marshal result: %v", err)
	}
	fmt.Println(string(json))
}