~huyngo/yue

abda7c15e0cb29f3fb7d7b3dff4465b78910c61a — Ngô Ngọc Đức Huy 11 months ago 55ec74f
Add version and utility structs
2 files changed, 60 insertions(+), 1 deletions(-)

M main.go
A structs.go
M main.go => main.go +6 -1
@@ 24,8 24,13 @@ import (
	"github.com/gorilla/mux"
)

var CurrentVersion string

func main() {
	r := mux.NewRouter()
	// Meta
	CurrentVersion = "0.0.0"

	r := mux.NewRouter().StrictSlash(true)
	fs := http.FileServer(http.Dir("assets/"))

	r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", fs))

A structs.go => structs.go +54 -0
@@ 0,0 1,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,
	}
}