Second Import
This commit is contained in:
@@ -4,31 +4,39 @@
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
import "errors"
|
||||
|
||||
// The config file
|
||||
type ConfigFile struct {
|
||||
Host string
|
||||
SessionName string
|
||||
SessionSecret string
|
||||
Apps []*App
|
||||
Host string // The host, eg: :8080 will start on 0.0.0.0:8080
|
||||
Apps []*App
|
||||
}
|
||||
|
||||
func (c ConfigFile) GetAppByAppID(appID string) (*App, error) {
|
||||
// Error for App not found
|
||||
var AppNotFoundError = errors.New("App not found")
|
||||
|
||||
func (c *ConfigFile) Initialize() {
|
||||
for _, app := range c.Apps {
|
||||
app.Subscribers = make(map[string]*Subscriber)
|
||||
}
|
||||
}
|
||||
|
||||
// Returns an App with by appID
|
||||
func (c *ConfigFile) GetAppByAppID(appID string) (*App, error) {
|
||||
for _, app := range c.Apps {
|
||||
if app.AppID == appID {
|
||||
return app, nil
|
||||
}
|
||||
}
|
||||
return &App{}, errors.New("App not found")
|
||||
return &App{}, AppNotFoundError
|
||||
}
|
||||
|
||||
func (c ConfigFile) GetAppByKey(key string) (*App, error) {
|
||||
// Returns an App with by key
|
||||
func (c *ConfigFile) GetAppByKey(key string) (*App, error) {
|
||||
for _, app := range c.Apps {
|
||||
if app.Key == key {
|
||||
return app, nil
|
||||
}
|
||||
}
|
||||
return &App{}, errors.New("App not found")
|
||||
return &App{}, AppNotFoundError
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user