aboutsummaryrefslogtreecommitdiff
path: root/grilist/grilist.go
blob: aebe45c5a3e8af8231d9093d62e614d2c75cfe70 (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
54
package grilist

import (
	"database/sql"
	"log"
	"net"
	"net/http"
	"strings"

	"fagott.pw/charakterin"
	"fagott.pw/grilist/eventlogging"
	"fagott.pw/grilist/frontend"

	"github.com/julienschmidt/httprouter"
	_ "github.com/lib/pq"
)

// Grilist struct
type Grilist struct {
	Config      Config
	Renderer    *frontend.Renderer
	Charakterin *charakterin.Charakterin
	DB          *sql.DB
	Modules     map[string]Module
	Router      *httprouter.Router
}

func (g *Grilist) EventLogger(r *http.Request) *eventlogging.EventLogger {
	forwardedIPs := strings.Split(r.Header.Get("X-Forwarded-For"), ", ")
	ip := r.RemoteAddr
	if len(forwardedIPs) > 0 && forwardedIPs[0] != "" {
		ip = forwardedIPs[0]
	}
	host, _, err := net.SplitHostPort(ip)
	if err != nil {
		log.Printf("Could not split IP %s\n", ip)
		log.Println(err)
		host = "0.0.0.0"
	}
	return eventlogging.NewEventLogger(host)
}

// Module ist ein Modul für Grilist.
type Module interface {
	Init(*Grilist)
	Name() string
	ProvideDashboardData(*charakterin.User) []DashboardCategory
}

// DashboardCategory ist eine Kategorie mit Karten, die auf dem Dashboard angezeigt werden.
type DashboardCategory struct {
	Title string
	Cards []frontend.Card
}