File structure organization.

Create a new package ipe and put everything n there except for the main function.
This commit is contained in:
claudemiro
2015-01-31 08:29:01 -03:00
parent c7f757e517
commit cd1fd8995d
22 changed files with 59 additions and 42 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package main
package ipe
import (
"errors"
+1 -1
View File
@@ -2,7 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package main
package ipe
import (
"strconv"
+1 -1
View File
@@ -2,7 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package main
package ipe
import (
"net/http"
+1 -1
View File
@@ -2,7 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package main
package ipe
import (
"encoding/json"
+1 -1
View File
@@ -2,7 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package main
package ipe
import "testing"
+1 -1
View File
@@ -2,7 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package main
package ipe
import (
"errors"
+1 -1
View File
@@ -2,7 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package main
package ipe
import (
log "github.com/golang/glog"
@@ -2,4 +2,4 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package main
package ipe
+1 -1
View File
@@ -2,7 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package main
package ipe
// Error Codes
const (
+1 -1
View File
@@ -2,7 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package main
package ipe
// Base interface
type WebsocketError interface {
+1 -1
View File
@@ -2,7 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package main
package ipe
import (
"encoding/json"
+1 -1
View File
@@ -2,7 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package main
package ipe
import (
"fmt"
+36
View File
@@ -0,0 +1,36 @@
// Copyright 2015 Claudemiro Alves Feitosa Neto. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package ipe
import (
"encoding/json"
"io/ioutil"
"net/http"
)
// Conf holds the global configuration state
var Conf ConfigFile
// Start Parse the configuration file and starts the ipe server
func Start(configfile string) error {
file, err := ioutil.ReadFile(configfile)
if err != nil {
return err
}
if err := json.Unmarshal(file, &Conf); err != nil {
return err
}
Conf.Init()
router := NewRouter()
if err := http.ListenAndServe(Conf.Host, router); err != nil {
return err
}
return nil
}
+1 -1
View File
@@ -2,7 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package main
package ipe
import (
"encoding/json"
View File
+1 -1
View File
@@ -2,7 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package main
package ipe
import (
_ "expvar"
+1 -1
View File
@@ -2,7 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package main
package ipe
import (
"net/http"
+1 -1
View File
@@ -2,7 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package main
package ipe
// A Channel Subscription
type Subscription struct {
+1 -1
View File
@@ -2,7 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package main
package ipe
import (
"bytes"
+1 -1
View File
@@ -2,7 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package main
package ipe
import (
"encoding/json"
+5 -24
View File
@@ -5,45 +5,26 @@
package main
import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"net/http"
"github.com/dimiro1/ipe/ipe"
log "github.com/golang/glog"
)
var Conf ConfigFile
// Main function, initialze the system
func main() {
printBanner()
var filename = flag.String("config", "config.json", "Config file location")
flag.Parse()
file, err := ioutil.ReadFile(*filename)
printBanner()
if err != nil {
log.Fatal(err)
}
if err := json.Unmarshal(file, &Conf); err != nil {
log.Fatal(err)
}
Conf.Init()
router := NewRouter()
log.Infof("Starting Ipê using config file: '%s'", *filename)
if err := http.ListenAndServe(Conf.Host, router); err != nil {
if err := ipe.Start(*filename); err != nil {
log.Fatal(err)
}
}
// Print a beatifull banner
func printBanner() {
fmt.Print("\033[36m")
fmt.Print(`