Fix some linting errors with error messages
This commit is contained in:
parent
bb0c3ea736
commit
6a2cb3f906
12
chatroom.go
12
chatroom.go
|
@ -46,7 +46,7 @@ func newChatRoom() (*ChatRoom, error) {
|
||||||
|
|
||||||
num, err := LoadEmotes()
|
num, err := LoadEmotes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Error loading emotes: %s", err)
|
return nil, fmt.Errorf("error loading emotes: %s", err)
|
||||||
}
|
}
|
||||||
fmt.Printf("Loaded %d emotes\n", num)
|
fmt.Printf("Loaded %d emotes\n", num)
|
||||||
|
|
||||||
|
@ -65,12 +65,12 @@ func LoadEmotes() (int, error) {
|
||||||
|
|
||||||
emotePNGs, err := filepath.Glob("./static/emotes/*.png")
|
emotePNGs, err := filepath.Glob("./static/emotes/*.png")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("Unable to glob emote directory: %s\n", err)
|
return 0, fmt.Errorf("unable to glob emote directory: %s\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
emoteGIFs, err := filepath.Glob("./static/emotes/*.gif")
|
emoteGIFs, err := filepath.Glob("./static/emotes/*.gif")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("Unable to glob emote directory: %s\n", err)
|
return 0, fmt.Errorf("unable to glob emote directory: %s\n", err)
|
||||||
}
|
}
|
||||||
globbed_files := []string(emotePNGs)
|
globbed_files := []string(emotePNGs)
|
||||||
globbed_files = append(globbed_files, emoteGIFs...)
|
globbed_files = append(globbed_files, emoteGIFs...)
|
||||||
|
@ -104,12 +104,12 @@ func (cr *ChatRoom) JoinTemp(conn *websocket.Conn) (string, error) {
|
||||||
|
|
||||||
uid, err := uuid.NewV4()
|
uid, err := uuid.NewV4()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("could not create uuid, %v", err)
|
return "", fmt.Errorf("could not create uuid: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
suid := uid.String()
|
suid := uid.String()
|
||||||
if _, ok := cr.tempConn[suid]; ok {
|
if _, ok := cr.tempConn[suid]; ok {
|
||||||
return "", errors.New("%#v is already in the temp connections")
|
return "", fmt.Errorf("%#v is already in the temp connections", suid)
|
||||||
}
|
}
|
||||||
|
|
||||||
cr.tempConn[suid] = conn
|
cr.tempConn[suid] = conn
|
||||||
|
@ -420,7 +420,7 @@ func (cr *ChatRoom) getClient(name string) (*Client, error) {
|
||||||
if client, ok := cr.clients[strings.ToLower(name)]; ok {
|
if client, ok := cr.clients[strings.ToLower(name)]; ok {
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("Client with that name not found.")
|
return nil, fmt.Errorf("client with that name not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cr *ChatRoom) generateModPass() string {
|
func (cr *ChatRoom) generateModPass() string {
|
||||||
|
|
12
settings.go
12
settings.go
|
@ -49,13 +49,13 @@ func init() {
|
||||||
func LoadSettings(filename string) (*Settings, error) {
|
func LoadSettings(filename string) (*Settings, error) {
|
||||||
raw, err := ioutil.ReadFile(filename)
|
raw, err := ioutil.ReadFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Error reading file: %s", err)
|
return nil, fmt.Errorf("error reading file: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var s *Settings
|
var s *Settings
|
||||||
err = json.Unmarshal(raw, &s)
|
err = json.Unmarshal(raw, &s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Error unmarshaling: %s", err)
|
return nil, fmt.Errorf("error unmarshaling: %s", err)
|
||||||
}
|
}
|
||||||
s.filename = filename
|
s.filename = filename
|
||||||
|
|
||||||
|
@ -63,12 +63,12 @@ func LoadSettings(filename string) (*Settings, error) {
|
||||||
if s.MaxMessageCount == 0 {
|
if s.MaxMessageCount == 0 {
|
||||||
s.MaxMessageCount = 300
|
s.MaxMessageCount = 300
|
||||||
} else if s.MaxMessageCount < 0 {
|
} else if s.MaxMessageCount < 0 {
|
||||||
return s, fmt.Errorf("MaxMessageCount value must be greater than 0, given %d", s.MaxMessageCount)
|
return s, fmt.Errorf("value for MaxMessageCount must be greater than 0, given %d", s.MaxMessageCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.AdminPassword, err = generatePass(time.Now().Unix())
|
s.AdminPassword, err = generatePass(time.Now().Unix())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Unable to generate admin password: %s", err)
|
return nil, fmt.Errorf("unable to generate admin password: %s", err)
|
||||||
}
|
}
|
||||||
fmt.Printf("Settings reloaded. New admin password: %s\n", s.AdminPassword)
|
fmt.Printf("Settings reloaded. New admin password: %s\n", s.AdminPassword)
|
||||||
|
|
||||||
|
@ -91,12 +91,12 @@ func generatePass(seed int64) (string, error) {
|
||||||
func (s *Settings) Save() error {
|
func (s *Settings) Save() error {
|
||||||
marshaled, err := json.MarshalIndent(s, "", "\t")
|
marshaled, err := json.MarshalIndent(s, "", "\t")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error marshaling: %s", err)
|
return fmt.Errorf("error marshaling: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ioutil.WriteFile(s.filename, marshaled, 0777)
|
err = ioutil.WriteFile(s.filename, marshaled, 0777)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error saving: %s", err)
|
return fmt.Errorf("error saving: %s", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue