Archived
1
0

fix stuff up

This commit is contained in:
Jeff Becker 2017-09-09 09:45:45 -04:00
parent 0cd12cf944
commit ea91db2f58
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05
7 changed files with 40 additions and 1 deletions

View File

@ -0,0 +1,8 @@
;; thanks stack overflow
;; https://stackoverflow.com/questions/4012321/how-can-i-access-the-path-to-the-current-directory-in-an-emacs-directory-variabl
((nil . ((eval . (set (make-local-variable 'my-project-path)
(file-name-directory
(let ((d (dir-locals-find-file ".")))
(if (stringp d) d (car d))))))
(eval . (setenv "GOPATH" my-project-path))
(eval . (message "Project directory set to `%s'." my-project-path)))))

View File

@ -95,13 +95,14 @@ func Main() {
} }
nserv.Hooks = hooks nserv.Hooks = hooks
} }
var frontends []frontend.Frontend
var db database.Database var db database.Database
for _, fconf := range conf.Frontends { for _, fconf := range conf.Frontends {
var f frontend.Frontend var f frontend.Frontend
f, err = frontend.NewHTTPFrontend(fconf, db) f, err = frontend.NewHTTPFrontend(fconf, db)
if err == nil { if err == nil {
go f.Serve() go f.Serve()
frontends = append(frontends, f)
} }
} }
@ -121,6 +122,15 @@ func Main() {
log.Infof("reloading config: %s", cfgFname) log.Infof("reloading config: %s", cfgFname)
nserv.ReloadServer(conf.NNTP) nserv.ReloadServer(conf.NNTP)
nserv.ReloadFeeds(conf.Feeds) nserv.ReloadFeeds(conf.Feeds)
for idx := range frontends {
f := frontends[idx]
for i := range conf.Frontends {
c := conf.Frontends[i]
if c != nil && c.Name() == f.Name() {
f.Reload(c)
}
}
}
} else { } else {
log.Errorf("failed to reload config: %s", err) log.Errorf("failed to reload config: %s", err)
} }

View File

@ -1,5 +1,9 @@
package config package config
import (
"fmt"
)
type FrontendConfig struct { type FrontendConfig struct {
// bind to address // bind to address
BindAddr string `json:"bind"` BindAddr string `json:"bind"`
@ -13,6 +17,10 @@ type FrontendConfig struct {
Middleware *MiddlewareConfig `json:"middleware"` Middleware *MiddlewareConfig `json:"middleware"`
} }
func (cfg *FrontendConfig) Name() string {
return fmt.Sprintf("frontend-%s", cfg.BindAddr)
}
// default Frontend Configuration // default Frontend Configuration
var DefaultFrontendConfig = FrontendConfig{ var DefaultFrontendConfig = FrontendConfig{
BindAddr: "127.0.0.1:18888", BindAddr: "127.0.0.1:18888",

View File

@ -27,6 +27,9 @@ type Frontend interface {
// reload config // reload config
Reload(c *config.FrontendConfig) Reload(c *config.FrontendConfig)
// get frontend name
Name() string
} }
// create a new http frontend give frontend config // create a new http frontend give frontend config

View File

@ -33,6 +33,10 @@ type httpFrontend struct {
db database.Database db database.Database
} }
func (f *httpFrontend) Name() string {
return fmt.Sprintf("frontend-%s", f.addr)
}
// reload http frontend // reload http frontend
// reloads middleware // reloads middleware
func (f *httpFrontend) Reload(c *config.FrontendConfig) { func (f *httpFrontend) Reload(c *config.FrontendConfig) {

View File

@ -97,6 +97,7 @@ func (sd *socksDialer) Dial(remote string) (c net.Conn, err error) {
}).Warn("connect via socks proxy failed") }).Warn("connect via socks proxy failed")
c.Close() c.Close()
c = nil c = nil
err = errors.New("could not connect via socks proxy")
} }
} else { } else {
// error reading reply // error reading reply
@ -106,6 +107,7 @@ func (sd *socksDialer) Dial(remote string) (c net.Conn, err error) {
}).Error("failed to read socks response ", err) }).Error("failed to read socks response ", err)
c.Close() c.Close()
c = nil c = nil
err = errors.New("socks proxy gave no reply")
} }
} else { } else {
if err == nil { if err == nil {

View File

@ -622,6 +622,10 @@ func (c *v1Conn) printfLine(format string, args ...interface{}) error {
} }
func (c *v1Conn) readline() (line string, err error) { func (c *v1Conn) readline() (line string, err error) {
if c.C == nil || c.C.R == nil {
err = errors.New("connection closed")
return
}
line, err = c.C.ReadLine() line, err = c.C.ReadLine()
log.WithFields(log.Fields{ log.WithFields(log.Fields{
"pkg": "nntp-conn", "pkg": "nntp-conn",