Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ $ gogo -h
# create a new application
$ gogo new myapp

# fix application import path
# resolve dependences
$ cd myapp
$ source env.sh
$ make

# generate controller
# NOTE: you should update application.go and add app.Resource("/user", User) route by hand
Expand Down Expand Up @@ -130,6 +130,8 @@ func main() {

- Using group

Group is useful when defining resources with shared middlewares and the same uri prefix.

```go
package main

Expand All @@ -142,7 +144,7 @@ import (
)

func main() {
app := gogo.New("development", "")
app := gogo.NewDefaults()

// avoid server quit by registering recovery func global
app.Use(func(ctx *gogo.Context) {
Expand Down
21 changes: 21 additions & 0 deletions cmd/gogo/templates/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var (

import (
"github.com/dolab/gogo"
"github.com/dolab/gogo/pkgs/hooks"

"{{.Namespace}}/{{.Application}}/app/middlewares"
"{{.Namespace}}/{{.Application}}/app/models"
Expand Down Expand Up @@ -52,5 +53,25 @@ func (app *Application) Resources() {

app.v1.GET("/@greeting/hello", GettingStart.Hello)
}

// // RequestReceivedHooks allows custom request received hooks of server
// func (app *Application) RequestReceivedHooks() []hooks.NamedHook {
// return nil
// }

// // RequestRoutedHooks allows custom request routed hooks of server
// func (app *Application) RequestRoutedHooks() []hooks.NamedHook {
// return nil
// }

// // RequestReceivedHooks allows custom response ready hooks of server
// func (app *Application) ResponseReadyHooks() []hooks.NamedHook {
// return nil
// }

// // RequestReceivedHooks allows custom response always hooks of server
// func (app *Application) ResponseAlwaysHooks() []hooks.NamedHook {
// return nil
// }
`
)
26 changes: 26 additions & 0 deletions cmd/gogo/templates/readme.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,32 @@ $ # run development server
$ make godev
</bash>

### Custom Server

You can custom Server by implementing interfaces following:

<golang>
// A RequestReceivedHooker represents request received hook interface of server
type RequestReceivedHooker interface {
RequestReceivedHooks() []hooks.NamedHook
}

// A RequestRoutedHooker represents request routed hook interface of server
type RequestRoutedHooker interface {
RequestRoutedHooks() []hooks.NamedHook
}

// A ResponseReadyHooker represents response ready for sending data hook interface of server
type ResponseReadyHooker interface {
ResponseReadyHooks() []hooks.NamedHook
}

// A ResponseAlwaysHooker represents response routed success hook interface of server
type ResponseAlwaysHooker interface {
ResponseAlwaysHooks() []hooks.NamedHook
}
</golang>

### APP Struct

<bash>
Expand Down
13 changes: 12 additions & 1 deletion config_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
package gogo

import (
"io/ioutil"
"os"
"path"
"strconv"
"strings"
"testing"

"github.com/golib/assert"
)

var (
fakePort = 19090
fakeConfig = func(name string) (*AppConfig, error) {
root, _ := os.Getwd()

return NewAppConfig(path.Join(root, "skeleton", "config", name))
data, err := ioutil.ReadFile(path.Join(root, "skeleton", "config", name))
if err != nil {
panic(err)
}

fakePort++

return NewAppConfigFromString(strings.Replace(string(data), "9090", strconv.Itoa(fakePort), -1))
}
)

Expand Down
Loading