syntax fixes
This commit is contained in:
parent
8e748aaa90
commit
1ce33aa89a
13 changed files with 45 additions and 43 deletions
14
pkg/cache/cache.go
vendored
14
pkg/cache/cache.go
vendored
|
|
@ -14,7 +14,7 @@ type CachedPage struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Cache struct {
|
type Cache struct {
|
||||||
sync.RWMutex
|
mu sync.RWMutex
|
||||||
Cache map[string]*CachedPage
|
Cache map[string]*CachedPage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -24,8 +24,8 @@ func NewCache() *Cache {
|
||||||
|
|
||||||
func (c *Cache) Add(title string, p *core.Page) {
|
func (c *Cache) Add(title string, p *core.Page) {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
c.Lock()
|
c.mu.Lock()
|
||||||
defer c.Unlock()
|
defer c.mu.Unlock()
|
||||||
cp, ok := c.Cache[title]
|
cp, ok := c.Cache[title]
|
||||||
if ok && now.After(cp.CacheTime) {
|
if ok && now.After(cp.CacheTime) {
|
||||||
cp.Page = p
|
cp.Page = p
|
||||||
|
|
@ -37,8 +37,8 @@ func (c *Cache) Add(title string, p *core.Page) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cache) Get(title string) (p *core.Page) {
|
func (c *Cache) Get(title string) (p *core.Page) {
|
||||||
c.RLock()
|
c.mu.RLock()
|
||||||
defer c.RUnlock()
|
defer c.mu.RUnlock()
|
||||||
if cp, ok := c.Cache[title]; ok {
|
if cp, ok := c.Cache[title]; ok {
|
||||||
p = new(core.Page)
|
p = new(core.Page)
|
||||||
*p = *cp.Page
|
*p = *cp.Page
|
||||||
|
|
@ -48,7 +48,7 @@ func (c *Cache) Get(title string) (p *core.Page) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cache) Delete(title string) {
|
func (c *Cache) Delete(title string) {
|
||||||
c.Lock()
|
c.mu.Lock()
|
||||||
delete(c.Cache, title)
|
delete(c.Cache, title)
|
||||||
c.Unlock()
|
c.mu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ var (
|
||||||
configFile string
|
configFile string
|
||||||
)
|
)
|
||||||
|
|
||||||
func initServer(cfg core.Config) (err error) {
|
func initServer(cfg *core.Config) (err error) {
|
||||||
// remove initial pledge due to violation with go1.12
|
// remove initial pledge due to violation with go1.12
|
||||||
// sysctl kern.somaxconn
|
// sysctl kern.somaxconn
|
||||||
// if err = godrop.PledgePromises("stdio rpath wpath cpath inet fattr flock proc exec id unveil"); err != nil {
|
// if err = godrop.PledgePromises("stdio rpath wpath cpath inet fattr flock proc exec id unveil"); err != nil {
|
||||||
|
|
@ -117,7 +117,7 @@ func Run(version string) {
|
||||||
stdlog.Fatal("server: ", err)
|
stdlog.Fatal("server: ", err)
|
||||||
}
|
}
|
||||||
config.Version = app.Version
|
config.Version = app.Version
|
||||||
if err := initServer(config); err != nil {
|
if err := initServer(&config); err != nil {
|
||||||
stdlog.Fatal("server: ", err)
|
stdlog.Fatal("server: ", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -137,12 +137,12 @@ func Run(version string) {
|
||||||
}
|
}
|
||||||
log.Stderr()
|
log.Stderr()
|
||||||
if dumpFile != "-" {
|
if dumpFile != "-" {
|
||||||
file, err = os.OpenFile(dumpFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
|
file, err = os.OpenFile(dumpFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
stdlog.Fatal("dump: ", err)
|
stdlog.Fatal("dump: ", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DB, err := db.NewPlain(config)
|
DB, err := db.NewPlain(&config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
stdlog.Fatal("dump: ", err)
|
stdlog.Fatal("dump: ", err)
|
||||||
}
|
}
|
||||||
|
|
@ -175,7 +175,7 @@ func Run(version string) {
|
||||||
stdlog.Fatal("restore: ", err)
|
stdlog.Fatal("restore: ", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DB, err := db.NewPlain(config)
|
DB, err := db.NewPlain(&config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
stdlog.Fatal("restore: ", err)
|
stdlog.Fatal("restore: ", err)
|
||||||
}
|
}
|
||||||
|
|
@ -199,7 +199,7 @@ func Run(version string) {
|
||||||
if err = loadConfig(); err != nil {
|
if err = loadConfig(); err != nil {
|
||||||
stdlog.Fatal("resetadmin: ", err)
|
stdlog.Fatal("resetadmin: ", err)
|
||||||
}
|
}
|
||||||
DB, err := db.NewPlain(config)
|
DB, err := db.NewPlain(&config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
stdlog.Fatal("resetadmin: ", err)
|
stdlog.Fatal("resetadmin: ", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ type User struct {
|
||||||
Locked int
|
Locked int
|
||||||
}
|
}
|
||||||
|
|
||||||
type Users []User
|
type Users []*User
|
||||||
|
|
||||||
func (u Users) Len() int { return len(u) }
|
func (u Users) Len() int { return len(u) }
|
||||||
func (u Users) Swap(i, j int) { u[i], u[j] = u[j], u[i] }
|
func (u Users) Swap(i, j int) { u[i], u[j] = u[j], u[i] }
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ type DB struct {
|
||||||
indexPath string
|
indexPath string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPlain(cfg core.Config) (db *DB, err error) {
|
func NewPlain(cfg *core.Config) (db *DB, err error) {
|
||||||
db = &DB{admin: cfg.Admin, cache: cache.NewCache()}
|
db = &DB{admin: cfg.Admin, cache: cache.NewCache()}
|
||||||
dbFile := filepath.Join(cfg.DataDir, storeFile)
|
dbFile := filepath.Join(cfg.DataDir, storeFile)
|
||||||
err = godrop.Unveil(dbFile, "rwc")
|
err = godrop.Unveil(dbFile, "rwc")
|
||||||
|
|
@ -45,7 +45,7 @@ func NewPlain(cfg core.Config) (db *DB, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(cfg core.Config) (db *DB, err error) {
|
func New(cfg *core.Config) (db *DB, err error) {
|
||||||
db, err = NewPlain(cfg)
|
db, err = NewPlain(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,11 @@ func (db *DB) GetAllSections(username string, admin bool) (sections core.Section
|
||||||
}
|
}
|
||||||
p, err := db.getPage(k, username)
|
p, err := db.getPage(k, username)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
s := k[:strings.Index(k, "/")]
|
i := strings.Index(k, "/")
|
||||||
|
if i == -1 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
s := k[:i]
|
||||||
if _, ok := m[s]; !ok {
|
if _, ok := m[s]; !ok {
|
||||||
m[s] = core.UpdatedPages{}
|
m[s] = core.UpdatedPages{}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,21 +40,22 @@ func (db *DB) GetUsers() (users core.Users, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) GetUserWithoutPassword(username string) (u core.User, err error) {
|
func (db *DB) GetUserWithoutPassword(username string) (u *core.User, err error) {
|
||||||
u, err = db.GetUser(username)
|
u, err = db.GetUser(username)
|
||||||
u.Password = ""
|
u.Password = ""
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) GetUserSecret(username string) (secret string, err error) {
|
func (db *DB) GetUserSecret(username string) (secret string, err error) {
|
||||||
var user core.User
|
var user *core.User
|
||||||
user, err = db.GetUser(username)
|
user, err = db.GetUser(username)
|
||||||
secret = user.Secret
|
secret = user.Secret
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) GetUser(username string) (u core.User, err error) {
|
func (db *DB) GetUser(username string) (u *core.User, err error) {
|
||||||
err = db.store.Get(userPrefix+username, &u)
|
u = new(core.User)
|
||||||
|
err = db.store.Get(userPrefix+username, u)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -86,7 +87,7 @@ func (db *DB) CreateUser(username, password string, admin bool) error {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) Login(username, password string) (u core.User, err error) {
|
func (db *DB) Login(username, password string) (u *core.User, err error) {
|
||||||
if username == defUser && !db.admin {
|
if username == defUser && !db.admin {
|
||||||
err = errors.New("db: user disabled")
|
err = errors.New("db: user disabled")
|
||||||
return
|
return
|
||||||
|
|
@ -118,7 +119,7 @@ func (db *DB) Login(username, password string) (u core.User, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) Totp(username, pin string) (u core.User, err error) {
|
func (db *DB) Totp(username, pin string) (u *core.User, err error) {
|
||||||
u, err = db.GetUser(username)
|
u, err = db.GetUser(username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|
@ -147,7 +148,7 @@ func (db *DB) Totp(username, pin string) (u core.User, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) UnlockUser(username string) (err error) {
|
func (db *DB) UnlockUser(username string) (err error) {
|
||||||
var u core.User
|
var u *core.User
|
||||||
u, err = db.GetUser(username)
|
u, err = db.GetUser(username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ func New(path string) (i *Index, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if _, err = os.Stat(path); os.IsNotExist(err) {
|
if _, err = os.Stat(path); os.IsNotExist(err) {
|
||||||
err = os.Mkdir(path, 0700)
|
err = os.Mkdir(path, 0o700)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.New("index: " + err.Error())
|
err = errors.New("index: " + err.Error())
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ func Stderr() {
|
||||||
log = stdlog.New(os.Stderr, "", stdlog.LstdFlags)
|
log = stdlog.New(os.Stderr, "", stdlog.LstdFlags)
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitLogger(cfg core.Config) {
|
func InitLogger(cfg *core.Config) {
|
||||||
debug = cfg.Debug
|
debug = cfg.Debug
|
||||||
if cfg.LogFile == "-" {
|
if cfg.LogFile == "-" {
|
||||||
return
|
return
|
||||||
|
|
@ -30,7 +30,7 @@ func InitLogger(cfg core.Config) {
|
||||||
stdlog.Fatal(err)
|
stdlog.Fatal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
f, err := os.OpenFile(logfile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0600)
|
f, err := os.OpenFile(logfile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0o600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
stdlog.Fatal(err)
|
stdlog.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ package render
|
||||||
import (
|
import (
|
||||||
"git.giftfish.de/ston1th/gowiki/pkg/core"
|
"git.giftfish.de/ston1th/gowiki/pkg/core"
|
||||||
"github.com/blevesearch/bleve/analysis"
|
"github.com/blevesearch/bleve/analysis"
|
||||||
"github.com/blevesearch/bleve/analysis/char/html"
|
htmlchar "github.com/blevesearch/bleve/analysis/char/html"
|
||||||
"github.com/russross/blackfriday"
|
"github.com/russross/blackfriday"
|
||||||
"html/template"
|
"html/template"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
@ -17,7 +17,7 @@ const delim = "+"
|
||||||
var filter = makeFilter()
|
var filter = makeFilter()
|
||||||
|
|
||||||
func makeFilter() analysis.CharFilter {
|
func makeFilter() analysis.CharFilter {
|
||||||
f, _ := html.CharFilterConstructor(nil, nil)
|
f, _ := htmlchar.CharFilterConstructor(nil, nil)
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -246,7 +246,7 @@ func (c *Context) LogSetCookie(msg string, err error) {
|
||||||
c.SetCookie(nil, 0)
|
c.SetCookie(nil, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) Login(u core.User, remember string) {
|
func (c *Context) Login(u *core.User, remember string) {
|
||||||
var d time.Duration
|
var d time.Duration
|
||||||
if remember != "" {
|
if remember != "" {
|
||||||
d = day * 7
|
d = day * 7
|
||||||
|
|
|
||||||
|
|
@ -465,11 +465,9 @@ func pageHandler(ctx *Context) {
|
||||||
if ctx.T == nil {
|
if ctx.T == nil {
|
||||||
ctx.Template("pageViewHandler")
|
ctx.Template("pageViewHandler")
|
||||||
}
|
}
|
||||||
} else {
|
} else if ctx.T == nil {
|
||||||
if ctx.T == nil {
|
|
||||||
ctx.Template("pageHandler")
|
ctx.Template("pageHandler")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
page, err := ctx.Srv.DB.GetPage(section, title, user)
|
page, err := ctx.Srv.DB.GetPage(section, title, user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
|
|
@ -866,8 +864,7 @@ func statsHandler(ctx *Context) {
|
||||||
Title: "Stats",
|
Title: "Stats",
|
||||||
BodyTitle: "Stats",
|
BodyTitle: "Stats",
|
||||||
}
|
}
|
||||||
switch ctx.Method() {
|
if ctx.Method() == "GET" {
|
||||||
case "GET":
|
|
||||||
ctx.Data.Data = getStats(ctx.Srv.DB.Index)
|
ctx.Data.Data = getStats(ctx.Srv.DB.Index)
|
||||||
ctx.Exec()
|
ctx.Exec()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type HTTPServer struct {
|
type HTTPServer struct {
|
||||||
Config core.Config
|
Config *core.Config
|
||||||
|
|
||||||
listener net.Listener
|
listener net.Listener
|
||||||
srv *http.Server
|
srv *http.Server
|
||||||
|
|
@ -36,7 +36,7 @@ type HTTPServer struct {
|
||||||
res map[string][]byte
|
res map[string][]byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHTTPServer(cfg core.Config, l net.Listener) (srv *HTTPServer) {
|
func NewHTTPServer(cfg *core.Config, l net.Listener) (srv *HTTPServer) {
|
||||||
srv = &HTTPServer{
|
srv = &HTTPServer{
|
||||||
Config: cfg,
|
Config: cfg,
|
||||||
listener: l,
|
listener: l,
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defaultBoltBucket = "default"
|
defaultBoltBucket = "default"
|
||||||
fileMode = 0600
|
fileMode = 0o600
|
||||||
)
|
)
|
||||||
|
|
||||||
type BoltStore struct {
|
type BoltStore struct {
|
||||||
|
|
@ -26,7 +26,7 @@ func NewBoltStore(file string, m Marshaler) (Store, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err = db.Update(func(tx *bolt.Tx) (err error) {
|
if err := db.Update(func(tx *bolt.Tx) (err error) {
|
||||||
_, err = tx.CreateBucketIfNotExists([]byte(defaultBoltBucket))
|
_, err = tx.CreateBucketIfNotExists([]byte(defaultBoltBucket))
|
||||||
return
|
return
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue