Permalink
Browse files

Use oftn-oswg/socket

  • Loading branch information...
dsamarin committed May 20, 2018
1 parent 475a159 commit b9712a94bbfca597a79be1dd160000ebda3ca387
Showing with 14 additions and 35 deletions.
  1. +3 −0 .gitignore
  2. +3 −3 admin.go
  3. +4 −1 main.go
  4. +4 −31 zerodrop.go
@@ -8,3 +8,6 @@ zerodrop
# Webpack
/node_modules/
# IDEs
/.vscode/
@@ -74,7 +74,7 @@ func (a *AdminHandler) ServeLogin(w http.ResponseWriter, r *http.Request) {
}
data := &AdminPageData{Title: "Zerodrop Login", Config: a.Config}
loginTmpl := a.Templates.Lookup("admin-login.tmpl")
loginTmpl := a.Templates.Lookup("login.tmpl")
err := loginTmpl.ExecuteTemplate(w, "login", data)
if err != nil {
log.Println(err)
@@ -180,7 +180,7 @@ func (a *AdminHandler) ServeNew(w http.ResponseWriter, r *http.Request) {
}
data := &AdminPageData{Title: "Zerodrop New", LoggedIn: true, Config: a.Config}
loginTmpl := a.Templates.Lookup("admin-new.tmpl")
loginTmpl := a.Templates.Lookup("new.tmpl")
err := loginTmpl.ExecuteTemplate(w, "new", data)
if err != nil {
log.Println(err)
@@ -236,7 +236,7 @@ func (a *AdminHandler) ServeMain(w http.ResponseWriter, r *http.Request) {
var err error
data.Entries, err = a.DB.List()
interfaceTmpl := a.Templates.Lookup("admin-main.tmpl")
interfaceTmpl := a.Templates.Lookup("main.tmpl")
if interfaceTmpl.ExecuteTemplate(w, "main", data) != nil {
log.Println(err)
}
@@ -25,7 +25,10 @@ func main() {
log.Printf("Loaded configuration: %#v", config)
app := NewZerodropApp(&config)
app.Start()
err := app.Start()
if err != nil {
log.Fatal(err)
}
signalChan := make(chan os.Signal)
signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
@@ -3,11 +3,10 @@ package main
import (
"context"
"log"
"net"
"net/http"
"os"
"os/user"
"strconv"
"github.com/oftn-oswg/socket"
)
// ZerodropConfig holds the configuration for an application instance.
@@ -78,37 +77,11 @@ func (z *ZerodropApp) Start() error {
config := z.Config
db := z.DB
network, address := ParseSocketName(config.Listen)
if network == "unix" {
os.Remove(address)
}
socket, err := net.Listen(network, address)
network, address := socket.Parse(config.Listen)
socket, err := socket.Listen(network, address, 0660)
if err != nil {
return err
}
defer socket.Close()
if network == "unix" {
if config.Group != "" {
uid := os.Geteuid()
group, err := user.LookupGroup(config.Group)
if err != nil {
return err
}
gid, err := strconv.Atoi(group.Gid)
if err != nil {
return err
}
if err := os.Chown(address, uid, gid); err != nil {
return err
}
}
if err := os.Chmod(address, 0660); err != nil {
return err
}
}
if err := db.Connect(config.DB.Driver, config.DB.Source); err != nil {
return err

0 comments on commit b9712a9

Please sign in to comment.