summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-12-31 09:56:21 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-12-31 09:56:21 (GMT)
commit016803268a21b5b341760875ea692c58d185dbda (patch)
tree9bda884d90644233cad969cd12d5fea372c97492 /src
parent0ef8fcb03fc4f51b8bc6b1a24f2e964b6a03d50c (diff)
improved coding style
Diffstat (limited to 'src')
-rw-r--r--src/helsinki.at/rhimportd/ctrlTelnet.go60
-rw-r--r--src/helsinki.at/rhimportd/ctrlWeb.go6
-rw-r--r--src/helsinki.at/rhimportd/ctrlWebSimple.go5
-rw-r--r--src/helsinki.at/rhimportd/ctrlWebSocket.go16
-rw-r--r--src/helsinki.at/rhimportd/main.go18
5 files changed, 52 insertions, 53 deletions
diff --git a/src/helsinki.at/rhimportd/ctrlTelnet.go b/src/helsinki.at/rhimportd/ctrlTelnet.go
index 4ea7c66..7373de3 100644
--- a/src/helsinki.at/rhimportd/ctrlTelnet.go
+++ b/src/helsinki.at/rhimportd/ctrlTelnet.go
@@ -33,11 +33,11 @@ import (
"strings"
)
-func telnet_quit(c *telgo.TelnetClient, args []string, conf *rhimport.Config, rddb *rhimport.RdDbChan) bool {
+func telnetQuit(c *telgo.TelnetClient, args []string, conf *rhimport.Config, rddb *rhimport.RdDbChan) bool {
return true
}
-func telnet_help(c *telgo.TelnetClient, args []string, conf *rhimport.Config, rddb *rhimport.RdDbChan) bool {
+func telnetHelp(c *telgo.TelnetClient, args []string, conf *rhimport.Config, rddb *rhimport.RdDbChan) bool {
switch len(args) {
case 2:
switch args[1] {
@@ -121,7 +121,7 @@ func telnet_help(c *telgo.TelnetClient, args []string, conf *rhimport.Config, rd
return false
}
-func telnet_set_int(c *telgo.TelnetClient, param *int, val string) {
+func telnetSetInt(c *telgo.TelnetClient, param *int, val string) {
if vint, err := strconv.ParseInt(val, 10, 32); err != nil {
c.Sayln("invalid value (must be an integer)")
} else {
@@ -129,7 +129,7 @@ func telnet_set_int(c *telgo.TelnetClient, param *int, val string) {
}
}
-func telnet_set_uint(c *telgo.TelnetClient, param *uint, val string) {
+func telnetSetUint(c *telgo.TelnetClient, param *uint, val string) {
if vuint, err := strconv.ParseUint(val, 10, 32); err != nil {
c.Sayln("invalid value (must be a positive integer)")
} else {
@@ -137,7 +137,7 @@ func telnet_set_uint(c *telgo.TelnetClient, param *uint, val string) {
}
}
-func telnet_set_bool(c *telgo.TelnetClient, param *bool, val string) {
+func telnetSetBool(c *telgo.TelnetClient, param *bool, val string) {
if vbool, err := strconv.ParseBool(val); err != nil {
c.Sayln("invalid value (must be true or false)")
} else {
@@ -145,7 +145,7 @@ func telnet_set_bool(c *telgo.TelnetClient, param *bool, val string) {
}
}
-func telnet_set(c *telgo.TelnetClient, args []string, conf *rhimport.Config, rddb *rhimport.RdDbChan) bool {
+func telnetSet(c *telgo.TelnetClient, args []string, conf *rhimport.Config, rddb *rhimport.RdDbChan) bool {
if len(args) != 3 {
c.Sayln("wrong number of arguments")
return false
@@ -167,32 +167,32 @@ func telnet_set(c *telgo.TelnetClient, args []string, conf *rhimport.Config, rdd
case "sourceuri":
ctx.SourceUri = args[2]
case "showid":
- telnet_set_uint(c, &ctx.ShowId, args[2])
+ telnetSetUint(c, &ctx.ShowId, args[2])
case "clearshowcarts":
- telnet_set_bool(c, &ctx.ClearShowCarts, args[2])
+ telnetSetBool(c, &ctx.ClearShowCarts, args[2])
case "groupname":
ctx.GroupName = args[2]
case "cart":
- telnet_set_uint(c, &ctx.Cart, args[2])
+ telnetSetUint(c, &ctx.Cart, args[2])
case "clearcart":
- telnet_set_bool(c, &ctx.ClearCart, args[2])
+ telnetSetBool(c, &ctx.ClearCart, args[2])
case "cut":
- telnet_set_uint(c, &ctx.Cut, args[2])
+ telnetSetUint(c, &ctx.Cut, args[2])
case "channels":
- telnet_set_uint(c, &ctx.Channels, args[2])
+ telnetSetUint(c, &ctx.Channels, args[2])
case "normalizationlevel":
- telnet_set_int(c, &ctx.NormalizationLevel, args[2])
+ telnetSetInt(c, &ctx.NormalizationLevel, args[2])
case "autotrimlevel":
- telnet_set_int(c, &ctx.AutotrimLevel, args[2])
+ telnetSetInt(c, &ctx.AutotrimLevel, args[2])
case "usemetadata":
- telnet_set_bool(c, &ctx.UseMetaData, args[2])
+ telnetSetBool(c, &ctx.UseMetaData, args[2])
default:
c.Sayln("unknown parameter, use 'help set' for a list of available parameters")
}
return false
}
-func telnet_reset(c *telgo.TelnetClient, args []string, conf *rhimport.Config, rddb *rhimport.RdDbChan) bool {
+func telnetReset(c *telgo.TelnetClient, args []string, conf *rhimport.Config, rddb *rhimport.RdDbChan) bool {
if len(args) > 1 {
c.Sayln("too many arguments")
return false
@@ -202,7 +202,7 @@ func telnet_reset(c *telgo.TelnetClient, args []string, conf *rhimport.Config, r
return false
}
-func telnet_show(c *telgo.TelnetClient, args []string, conf *rhimport.Config, rddb *rhimport.RdDbChan) bool {
+func telnetShow(c *telgo.TelnetClient, args []string, conf *rhimport.Config, rddb *rhimport.RdDbChan) bool {
if len(args) > 1 {
c.Sayln("too many arguments")
return false
@@ -229,13 +229,13 @@ func telnet_show(c *telgo.TelnetClient, args []string, conf *rhimport.Config, rd
return false
}
-func telnet_progress_callback(step int, step_name string, progress float64, userdata interface{}) bool {
+func telnetProgressCallback(step int, stepName string, progress float64, userdata interface{}) bool {
c := userdata.(*telgo.TelnetClient)
- c.Say("%s: %3.2f%%\r", step_name, progress*100)
+ c.Say("%s: %3.2f%%\r", stepName, progress*100)
return true
}
-func telnet_run(c *telgo.TelnetClient, args []string, conf *rhimport.Config, rddb *rhimport.RdDbChan) bool {
+func telnetRun(c *telgo.TelnetClient, args []string, conf *rhimport.Config, rddb *rhimport.RdDbChan) bool {
if c.UserData == nil {
c.Sayln("context is empty please set at least one option")
return false
@@ -246,7 +246,7 @@ func telnet_run(c *telgo.TelnetClient, args []string, conf *rhimport.Config, rdd
return false
}
- ctx.ProgressCallBack = telnet_progress_callback
+ ctx.ProgressCallBack = telnetProgressCallback
ctx.ProgressCallBackData = c
ctx.Cancel = c.Cancel
@@ -275,17 +275,17 @@ func telnet_run(c *telgo.TelnetClient, args []string, conf *rhimport.Config, rdd
return false
}
-func StartControlTelnet(addr_s string, conf *rhimport.Config, rddb *rhimport.RdDbChan, sessions *rhimport.SessionStoreChan) {
+func StartControlTelnet(addr string, conf *rhimport.Config, rddb *rhimport.RdDbChan, sessions *rhimport.SessionStoreChan) {
cmdlist := make(telgo.TelgoCmdList)
- cmdlist["quit"] = func(c *telgo.TelnetClient, args []string) bool { return telnet_quit(c, args, conf, rddb) }
- cmdlist["help"] = func(c *telgo.TelnetClient, args []string) bool { return telnet_help(c, args, conf, rddb) }
- cmdlist["set"] = func(c *telgo.TelnetClient, args []string) bool { return telnet_set(c, args, conf, rddb) }
- cmdlist["reset"] = func(c *telgo.TelnetClient, args []string) bool { return telnet_reset(c, args, conf, rddb) }
- cmdlist["show"] = func(c *telgo.TelnetClient, args []string) bool { return telnet_show(c, args, conf, rddb) }
- cmdlist["run"] = func(c *telgo.TelnetClient, args []string) bool { return telnet_run(c, args, conf, rddb) }
+ cmdlist["quit"] = func(c *telgo.TelnetClient, args []string) bool { return telnetQuit(c, args, conf, rddb) }
+ cmdlist["help"] = func(c *telgo.TelnetClient, args []string) bool { return telnetHelp(c, args, conf, rddb) }
+ cmdlist["set"] = func(c *telgo.TelnetClient, args []string) bool { return telnetSet(c, args, conf, rddb) }
+ cmdlist["reset"] = func(c *telgo.TelnetClient, args []string) bool { return telnetReset(c, args, conf, rddb) }
+ cmdlist["show"] = func(c *telgo.TelnetClient, args []string) bool { return telnetShow(c, args, conf, rddb) }
+ cmdlist["run"] = func(c *telgo.TelnetClient, args []string) bool { return telnetRun(c, args, conf, rddb) }
- rhl.Println("telnet-ctrl: listening on", addr_s)
- s := telgo.NewTelnetServer(addr_s, "rhimportd> ", cmdlist, nil)
+ rhl.Println("telnet-ctrl: listening on", addr)
+ s := telgo.NewTelnetServer(addr, "rhimportd> ", cmdlist, nil)
if err := s.Run(); err != nil {
fmt.Printf("telnet server returned: %s", err)
}
diff --git a/src/helsinki.at/rhimportd/ctrlWeb.go b/src/helsinki.at/rhimportd/ctrlWeb.go
index 794f8aa..14173da 100644
--- a/src/helsinki.at/rhimportd/ctrlWeb.go
+++ b/src/helsinki.at/rhimportd/ctrlWeb.go
@@ -43,13 +43,13 @@ func (self webHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
self.H(self.Config, self.RdDbChan, self.SessionStoreChan, self.trusted, w, r)
}
-func StartControlWeb(addr_s string, conf *rhimport.Config, rddb *rhimport.RdDbChan, sessions *rhimport.SessionStoreChan) {
+func StartControlWeb(addr string, conf *rhimport.Config, rddb *rhimport.RdDbChan, sessions *rhimport.SessionStoreChan) {
http.Handle("/public/simple", webHandler{conf, rddb, sessions, false, webSimpleHandler})
http.Handle("/trusted/simple", webHandler{conf, rddb, sessions, true, webSimpleHandler})
http.Handle("/public/socket", webHandler{conf, rddb, sessions, false, webSocketHandler})
- rhl.Println("web-ctrl: listening on", addr_s)
- server := &http.Server{Addr: addr_s, ReadTimeout: 60 * time.Second, WriteTimeout: 60 * time.Second}
+ rhl.Println("web-ctrl: listening on", addr)
+ server := &http.Server{Addr: addr, ReadTimeout: 60 * time.Second, WriteTimeout: 60 * time.Second}
server.ListenAndServe()
}
diff --git a/src/helsinki.at/rhimportd/ctrlWebSimple.go b/src/helsinki.at/rhimportd/ctrlWebSimple.go
index 12e17a3..7a7af92 100644
--- a/src/helsinki.at/rhimportd/ctrlWebSimple.go
+++ b/src/helsinki.at/rhimportd/ctrlWebSimple.go
@@ -30,7 +30,6 @@ import (
"helsinki.at/rhimport"
"html"
"net/http"
- _ "net/http/pprof"
)
type webSimpleRequestData struct {
@@ -75,11 +74,11 @@ type webSimpleResponseData struct {
Cut uint `json:"CUT_NUMBER"`
}
-func webSimpleErrorResponse(w http.ResponseWriter, code int, error_str string) {
+func webSimpleErrorResponse(w http.ResponseWriter, code int, errStr string) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusInternalServerError)
encoder := json.NewEncoder(w)
- respdata := webSimpleResponseData{code, error_str, 0, 0}
+ respdata := webSimpleResponseData{code, errStr, 0, 0}
encoder.Encode(respdata)
}
diff --git a/src/helsinki.at/rhimportd/ctrlWebSocket.go b/src/helsinki.at/rhimportd/ctrlWebSocket.go
index 7ceb9c4..9549311 100644
--- a/src/helsinki.at/rhimportd/ctrlWebSocket.go
+++ b/src/helsinki.at/rhimportd/ctrlWebSocket.go
@@ -107,11 +107,11 @@ func sendWebSocketResponse(ws *websocket.Conn, rd interface{}) {
}
}
-func sendWebSocketErrorResponse(ws *websocket.Conn, code int, err_str string) {
+func sendWebSocketErrorResponse(ws *websocket.Conn, code int, errStr string) {
rd := &webSocketResponseBaseData{}
rd.ResponseCode = code
rd.Type = "error"
- rd.ErrorString = err_str
+ rd.ErrorString = errStr
sendWebSocketResponse(ws, rd)
}
@@ -134,7 +134,7 @@ func sendWebSocketListResponse(ws *websocket.Conn, sessions map[string]string) {
sendWebSocketResponse(ws, rd)
}
-func sendWebSocketProgressResponse(ws *websocket.Conn, id, refid string, step int, step_name string, progress float64) {
+func sendWebSocketProgressResponse(ws *websocket.Conn, id, refid string, step int, stepName string, progress float64) {
rd := &webSocketResponseProgressData{}
rd.ResponseCode = http.StatusOK
rd.Type = "progress"
@@ -142,16 +142,16 @@ func sendWebSocketProgressResponse(ws *websocket.Conn, id, refid string, step in
rd.Id = id
rd.RefId = refid
rd.Step = step
- rd.StepName = step_name
+ rd.StepName = stepName
rd.Progress = progress
sendWebSocketResponse(ws, rd)
}
-func sendWebSocketDoneResponse(ws *websocket.Conn, code int, err_str, id, refid string, cart, cut uint) {
+func sendWebSocketDoneResponse(ws *websocket.Conn, code int, errStr, id, refid string, cart, cut uint) {
rd := &webSocketResponseDoneData{}
rd.ResponseCode = code
rd.Type = "done"
- rd.ErrorString = err_str
+ rd.ErrorString = errStr
rd.Id = id
rd.RefId = refid
rd.Cart = cart
@@ -174,13 +174,13 @@ func newWebSocketSession() *webSocketSession {
return session
}
-func webSocketProgress(step int, step_name string, progress float64, userdata interface{}) bool {
+func webSocketProgress(step int, stepName string, progress float64, userdata interface{}) bool {
if math.IsNaN(progress) {
progress = 0.0
}
c := userdata.(chan<- rhimport.ProgressData)
select {
- case c <- rhimport.ProgressData{step, step_name, progress}:
+ case c <- rhimport.ProgressData{step, stepName, progress}:
default:
}
return true
diff --git a/src/helsinki.at/rhimportd/main.go b/src/helsinki.at/rhimportd/main.go
index 21c1246..3d5c0b1 100644
--- a/src/helsinki.at/rhimportd/main.go
+++ b/src/helsinki.at/rhimportd/main.go
@@ -41,12 +41,12 @@ var (
)
func main() {
- web_addr_s := flag.String("web-addr", ":4080", "addr:port to listen on")
- telnet_addr_s := flag.String("telnet-addr", ":4023", "addr:port to listen on")
- rdconf_s := flag.String("rdconf", "/etc/rd.conf", "path to the Rivendell config file")
- rdxport_url_s := flag.String("rdxport-url", "http://localhost/rd-bin/rdxport.cgi", "the url to the Rivendell web-api")
- temp_dir_s := flag.String("tmp-dir", os.TempDir(), "path to temporary files")
- local_fetch_dir_s := flag.String("local-fetch-dir", os.TempDir(), "path to files that can be imported using local://")
+ webAddr := flag.String("web-addr", ":4080", "addr:port to listen on")
+ telnetAddr := flag.String("telnet-addr", ":4023", "addr:port to listen on")
+ rdconf := flag.String("rdconf", "/etc/rd.conf", "path to the Rivendell config file")
+ rdxportUrl := flag.String("rdxport-url", "http://localhost/rd-bin/rdxport.cgi", "the url to the Rivendell web-api")
+ tempDir := flag.String("tmp-dir", os.TempDir(), "path to temporary files")
+ localFetchDir := flag.String("local-fetch-dir", os.TempDir(), "path to files that can be imported using local://")
help := flag.Bool("help", false, "show usage")
flag.Parse()
@@ -55,7 +55,7 @@ func main() {
return
}
- conf, err := rhimport.NewConfig(rdconf_s, rdxport_url_s, temp_dir_s, local_fetch_dir_s)
+ conf, err := rhimport.NewConfig(rdconf, rdxportUrl, tempDir, localFetchDir)
if err != nil {
rhl.Println("Error reading configuration:", err)
return
@@ -81,7 +81,7 @@ func main() {
go func() {
defer wg.Done()
rhl.Println("starting web-ctrl")
- StartControlWeb(*web_addr_s, conf, rddb.GetInterface(), sessions.GetInterface())
+ StartControlWeb(*webAddr, conf, rddb.GetInterface(), sessions.GetInterface())
rhl.Println("web-ctrl finished")
}()
@@ -89,7 +89,7 @@ func main() {
go func() {
defer wg.Done()
rhl.Println("starting telnet-ctrl")
- StartControlTelnet(*telnet_addr_s, conf, rddb.GetInterface(), sessions.GetInterface())
+ StartControlTelnet(*telnetAddr, conf, rddb.GetInterface(), sessions.GetInterface())
rhl.Println("telnet-ctrl finished")
}()