Skip to content

Commit

Permalink
publize elaeagnus
Browse files Browse the repository at this point in the history
  • Loading branch information
duguying committed May 25, 2016
1 parent e2ede3f commit 2933536
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
22 changes: 11 additions & 11 deletions elaeagnus.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ var (
)

// Http handler
type elaeagnus struct {
type Elaeagnus struct {
middlewares []interface{}
}

func Web() *elaeagnus {
return &elaeagnus{}
func Web() *Elaeagnus {
return &Elaeagnus{}
}

// define a serials controller as main controller for an uri pattern
func (ela *elaeagnus) Router(uri string, f ...interface{}) {
func (ela *Elaeagnus) Router(uri string, f ...interface{}) {
if strings.HasPrefix(uri, "@") {
panic("@ should not be prefix of uri")
} else if !strings.HasPrefix(uri, "/") {
Expand All @@ -43,7 +43,7 @@ func (ela *elaeagnus) Router(uri string, f ...interface{}) {
}
}

func (ela *elaeagnus) execInjection() {
func (ela *Elaeagnus) execInjection() {
var mids []interface{}

for i := 0; i < len(ela.middlewares); i++ {
Expand All @@ -64,7 +64,7 @@ func (ela *elaeagnus) execInjection() {
ela.middlewares = mids
}

func (ela *elaeagnus) parseInjectionObject(mid interface{}) interface{} {
func (ela *Elaeagnus) parseInjectionObject(mid interface{}) interface{} {
t := reflect.TypeOf(mid)
if t.Kind() == reflect.Func {
result, err := injectFuc(mid, ela.middlewares)
Expand All @@ -80,7 +80,7 @@ func (ela *elaeagnus) parseInjectionObject(mid interface{}) interface{} {
}
}

func (ela *elaeagnus) ServeHTTP(w http.ResponseWriter, r *http.Request) {
func (ela *Elaeagnus) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// package ctx
ctx := newContext(w, r)

Expand Down Expand Up @@ -145,15 +145,15 @@ func (ela *elaeagnus) ServeHTTP(w http.ResponseWriter, r *http.Request) {
responseLog(ctx)
}

func (ela *elaeagnus) servHTTP(port int) {
func (ela *Elaeagnus) servHTTP(port int) {
log.Pinkf("[ela] Listen Port %d\n", port)
err := http.ListenAndServe(fmt.Sprintf(":%d", port), ela)
if err != nil {
fmt.Printf("HTTP Server Start Failed Port [%d]\n%s", port, err)
}
}

func (ela *elaeagnus) servController(path string, ctx Context) {
func (ela *Elaeagnus) servController(path string, ctx Context) {
controller := getController(path)
if controller == nil {
servError(ctx, "<h2>404, File Not Exist</h2>", 404, false)
Expand Down Expand Up @@ -227,11 +227,11 @@ func (ela *elaeagnus) servController(path string, ctx Context) {
}
}

func (ela *elaeagnus) Run() {
func (ela *Elaeagnus) Run() {
ela.servHTTP(int(config.GetIntDefault("_", "port", 3000)))
}

func (ela *elaeagnus) Use(middleware interface{}) {
func (ela *Elaeagnus) Use(middleware interface{}) {
ela.middlewares = append(ela.middlewares, middleware)
}

Expand Down
2 changes: 1 addition & 1 deletion i18n_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestI18n(t *testing.T) {
req, _ := http.NewRequest("GET", "/", nil)
req.Body = ioutil.NopCloser(bytes.NewBufferString("This is my request body"))
// So(err, ShouldBeNil)
m := elaeagnus{}
m := Web()
m.ServeHTTP(resp, req)

})
Expand Down

0 comments on commit 2933536

Please sign in to comment.