~huyngo/yue

ref: 261b5ce561bde8a041fa3220ffce233db44f3324 yue/structs.go -rw-r--r-- 938 bytes
261b5ce5Ngô Ngọc Đức Huy Add create request to timeline 11 months ago
                                                                                
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 main

import (
	"github.com/leonelquinteros/gotext"
)

type RequestContext struct {
	Lang     string
	Loc      *gotext.Locale
	Page     *PageData
	Setting  *Preference
	LoggedIn *User
	Yue      *Meta
}

type PageData struct {
	Title       string
	Description string
}

type Preference struct {
	Theme string
}

type User struct {
	Id       int
	Username string
}

type Meta struct {
	Version   string
}

func CreateRequestContext(lang string, title string,
	description string, theme string) RequestContext {
	if lang == "" {
		lang = gotext.GetLanguage()
	}
	locale := gotext.NewLocale("./locales", lang)
	pageData := PageData{
		Title:       locale.Get(title),
		Description: locale.Get(description),
	}
	setting := Preference{Theme: theme}
	meta := Meta{Version: CurrentVersion}
	return RequestContext{
		Lang:     lang,
		Loc:      locale,
		Page:     &pageData,
		Setting:  &setting,
		LoggedIn: nil,
		Yue:      &meta,
	}
}