File structure organization.
Create a new package ipe and put everything n there except for the main function.
This commit is contained in:
+1
-1
@@ -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"
|
||||
@@ -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"
|
||||
@@ -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"
|
||||
@@ -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"
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
@@ -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
|
||||
@@ -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 (
|
||||
@@ -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 {
|
||||
@@ -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"
|
||||
@@ -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
@@ -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
|
||||
}
|
||||
@@ -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"
|
||||
@@ -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"
|
||||
@@ -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"
|
||||
@@ -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 {
|
||||
@@ -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"
|
||||
@@ -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,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(`
|
||||
|
||||
Reference in New Issue
Block a user