Skip to content

Commit

Permalink
Fixed err variable name. Updated godoc visible names and comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Sergeyev committed Sep 27, 2014
1 parent f4cc76f commit 95558d4
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 20 deletions.
8 changes: 4 additions & 4 deletions libwebsocketd/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"time"
)

var ScriptNotFoundError = errors.New("Script not found")
var ErrScriptNotFound = errors.New("Script not found")

// WebsocketdHandler is a single request information and processing structure, it handles WS requests out of all that daemon can handle (static, cgi, devconsole)
type WebsocketdHandler struct {
Expand All @@ -27,7 +27,7 @@ type WebsocketdHandler struct {
command string
}

// NewWebsocketdHandler constructs the struct and parses all required things in it...
// NewWebsocketdHandler constructs the handler struct. It also prepares *Info elements and generates process environment.
func NewWebsocketdHandler(s *WebsocketdServer, req *http.Request, log *LogScope) (wsh *WebsocketdHandler, err error) {
wsh = &WebsocketdHandler{server: s, Id: generateId()}
log.Associate("id", wsh.Id)
Expand Down Expand Up @@ -178,12 +178,12 @@ func GetURLInfo(path string, config *Config) (*URLInfo, error) {

// not a valid path
if err != nil {
return nil, ScriptNotFoundError
return nil, ErrScriptNotFound
}

// at the end of url but is a dir
if isLastPart && statInfo.IsDir() {
return nil, ScriptNotFoundError
return nil, ErrScriptNotFound
}

// we've hit a dir, carry on looking
Expand Down
4 changes: 2 additions & 2 deletions libwebsocketd/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestParsePathWithScriptDir(t *testing.T) {
if err == nil {
t.Error("non-existing file should fail")
}
if err != ScriptNotFoundError {
if err != ErrScriptNotFound {
t.Error("should fail with script not found")
}

Expand All @@ -77,7 +77,7 @@ func TestParsePathWithScriptDir(t *testing.T) {
if err == nil {
t.Error("non-existing dir should fail")
}
if err != ScriptNotFoundError {
if err != ErrScriptNotFound {
t.Error("should fail with script not found")
}
}
Expand Down
2 changes: 1 addition & 1 deletion libwebsocketd/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (h *WebsocketdServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {

handler, err := NewWebsocketdHandler(h, req, log)
if err != nil {
if err == ScriptNotFoundError {
if err == ErrScriptNotFound {
log.Access("session", "NOT FOUND: %s", err)
http.Error(w, "404 Not Found", 404)
} else {
Expand Down
15 changes: 5 additions & 10 deletions libwebsocketd/logscope.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package libwebsocketd

import (
"sync"
"time"
)

type LogLevel int
Expand All @@ -30,17 +29,17 @@ type LogScope struct {
Parent *LogScope // Parent scope
MinLevel LogLevel // Minimum log level to write out.
Mutex *sync.Mutex // Should be shared across all LogScopes that write to the same destination.
Associated []AssocPair // Additional data associated with scope
Associated []assocPair // Additional data associated with scope
LogFunc LogFunc
}

type AssocPair struct {
type assocPair struct {
Key string
Value string
}

func (l *LogScope) Associate(key string, value string) {
l.Associated = append(l.Associated, AssocPair{key, value})
l.Associated = append(l.Associated, assocPair{key, value})
}

func (l *LogScope) Debug(category string, msg string, args ...interface{}) {
Expand Down Expand Up @@ -72,7 +71,7 @@ func (parent *LogScope) NewLevel(logFunc LogFunc) *LogScope {
Parent: parent,
MinLevel: parent.MinLevel,
Mutex: parent.Mutex,
Associated: make([]AssocPair, 0),
Associated: make([]assocPair, 0),
LogFunc: logFunc}
}

Expand All @@ -81,14 +80,10 @@ func RootLogScope(minLevel LogLevel, logFunc LogFunc) *LogScope {
Parent: nil,
MinLevel: minLevel,
Mutex: &sync.Mutex{},
Associated: make([]AssocPair, 0),
Associated: make([]assocPair, 0),
LogFunc: logFunc}
}

func Timestamp() string {
return time.Now().Format(time.RFC1123Z)
}

func LevelFromString(s string) LogLevel {
switch s {
case "debug":
Expand Down
4 changes: 2 additions & 2 deletions libwebsocketd/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (p *ExternalProcess) wait() {
p.log.Debug("process", "Process completed, status: %s", p.cmd.ProcessState.String())
}

// LaunchProcess initializes ExternalProcess struct fields
// LaunchProcess initializes ExternalProcess struct fields. Command pipes for standard input/output are established and first consumer channel is returned.
func LaunchProcess(cmd *exec.Cmd, log *LogScope) (*ExternalProcess, <-chan string, error) {
// TODO: Investigate alternative approaches. exec.Cmd uses real OS pipes which spends new filehandler each.
stdout, err := cmd.StdoutPipe()
Expand Down Expand Up @@ -134,7 +134,7 @@ func (e *ExternalProcess) Pid() int {
return e.cmd.Process.Pid
}

// Subscribe allows someone to open process's
// Subscribe allows someone to open channel that contains process's stdout messages.
func (p *ExternalProcess) Subscribe() (<-chan string, error) {
p.cmux.Lock()
defer p.cmux.Unlock()
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/http"
"os"
"strings"
"time"

"github.com/joewalnes/websocketd/libwebsocketd"
)
Expand All @@ -29,7 +30,7 @@ func log(l *libwebsocketd.LogScope, level libwebsocketd.LogLevel, levelName stri
}

l.Mutex.Lock()
fmt.Printf("%s | %-6s | %-10s | %s | %s\n", libwebsocketd.Timestamp(), levelName, category, assocDump, fullMsg)
fmt.Printf("%s | %-6s | %-10s | %s | %s\n", time.Now().Format(time.RFC1123Z), levelName, category, assocDump, fullMsg)
l.Mutex.Unlock()
}

Expand Down

0 comments on commit 95558d4

Please sign in to comment.