~fmac/pasticcio

dcd4deae5f567c3074b6f309955c4e6a4f72123a — Francesco Camuffo a month ago 868041c
Config: include info URLs

- privacy policy
- source code
6 files changed, 22 insertions(+), 6 deletions(-)

M config.example.yaml
M config/default.go
M go.mod
M go.sum
M web/templates/layouts/master.html
M web/utils/utils.go
M config.example.yaml => config.example.yaml +4 -0
@@ 8,3 8,7 @@ webRootPath: /usr/share/webapps/pasticcio/public
db:
  driver: postgres
  url: postgres://pasticcio:password@localhost:5432/pasticcio?sslmode=disable

info:
  privacyUrl: https://man.sr.ht/~fmac/Pasticcio/privacy.md
  srcUrl: https://sr.ht/~fmac/Pasticcio/

M config/default.go => config/default.go +7 -0
@@ 13,6 13,8 @@ type Config struct {
	WebRootPath   string `mapstructure:"webRootPath"`

	Db Db `mapstructure:"db"`

	Info Info `mapstructure:"info"`
}

type Db struct {


@@ 20,6 22,11 @@ type Db struct {
	Url    string `mapstructure:"url"`
}

type Info struct {
	PrivacyUrl string `mapstructure:"privacyUrl"`
	SrcUrl     string `mapstructure:"srcUrl"`
}

func LoadConfig() (config Config, err error) {
	viper.SetConfigName("config")
	viper.SetConfigType("yaml")

M go.mod => go.mod +1 -0
@@ 5,6 5,7 @@ go 1.18
require (
	github.com/foolin/goview v0.3.0
	github.com/gin-gonic/gin v1.8.1
	github.com/jinzhu/copier v0.3.5
	github.com/lib/pq v1.10.6
	github.com/spf13/viper v1.12.0
	github.com/tabbed/pqtype v0.1.1

M go.sum => go.sum +2 -0
@@ 150,6 150,8 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jinzhu/copier v0.3.5 h1:GlvfUwHk62RokgqVNvYsku0TATCF7bAHVwEXoBh3iJg=
github.com/jinzhu/copier v0.3.5/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=

M web/templates/layouts/master.html => web/templates/layouts/master.html +3 -3
@@ 4,7 4,7 @@
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <title>{{.AppTitle}}</title>
    <title>{{ .AppTitle }}</title>

    <link rel="stylesheet" href="{{resHashedPath "/css/main.min.css" }}" />
  </head>


@@ 16,10 16,10 @@
      </span>
      <ul class="navbar-nav flex-column flex-sm-row">
        <li class="flex-sm-fill nav-link">
          <a href="https://man.sr.ht/~fmac/Pasticcio/privacy.md" class="d-block">privacy</a>
          <a href="{{ .Info.PrivacyUrl }}" class="d-block">privacy</a>
        </li>
        <li class="flex-sm-fill nav-link">
          <a href="https://sr.ht/~fmac/Pasticcio/" class="d-block">src</a>
          <a href="{{ .Info.SrcUrl }}" class="d-block">src</a>
        </li>
      </ul>
    </nav>

M web/utils/utils.go => web/utils/utils.go +5 -3
@@ 14,6 14,7 @@ import (

	"fmac.dev/pasticcio/config"
	"github.com/gin-gonic/gin"
	"github.com/jinzhu/copier"
)

var Funcs template.FuncMap


@@ 29,6 30,7 @@ func Init(conf *config.Config) {
	hMx.Lock()
	h = gin.H{
		"AppTitle": conf.AppTitle,
		"Info":     conf.Info,
	}
	hMx.Unlock()



@@ 50,9 52,9 @@ func NewH(vals gin.H) gin.H {
		ret[k] = v
	}
	hMx.RLock()
	for k, v := range h {
		ret[k] = v
	}
	// XXX: I hate so much that you can't deepcopy in Go that I rage-imported
	// copier. fuck it
	copier.CopyWithOption(&ret, &h, copier.Option{IgnoreEmpty: false, DeepCopy: true})
	hMx.RUnlock()
	return ret
}