mirror of
https://github.com/beego/bee.git
synced 2024-11-25 20:10:55 +00:00
commit
4ff3cf5ce8
59
hproseapp.go
59
hproseapp.go
@ -10,7 +10,7 @@
|
|||||||
* *
|
* *
|
||||||
* Build rpc application use Hprose base on beego *
|
* Build rpc application use Hprose base on beego *
|
||||||
* *
|
* *
|
||||||
* LastModified: Oct 13, 2014 *
|
* LastModified: Oct 31, 2016 *
|
||||||
* Author: Liu jian <laoliu@lanmv.com> *
|
* Author: Liu jian <laoliu@lanmv.com> *
|
||||||
* *
|
* *
|
||||||
\**********************************************************/
|
\**********************************************************/
|
||||||
@ -63,16 +63,41 @@ EnableDocs = true
|
|||||||
var hproseMaingo = `package main
|
var hproseMaingo = `package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
"{{.Appname}}/models"
|
"{{.Appname}}/models"
|
||||||
"github.com/hprose/hprose-go/hprose"
|
"github.com/hprose/hprose-golang/rpc"
|
||||||
|
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func logInvokeHandler(
|
||||||
|
name string,
|
||||||
|
args []reflect.Value,
|
||||||
|
context rpc.Context,
|
||||||
|
next rpc.NextInvokeHandler) (results []reflect.Value, err error) {
|
||||||
|
fmt.Printf("%s(%v) = ", name, args)
|
||||||
|
results, err = next(name, args, context)
|
||||||
|
fmt.Printf("%v %v\r\n", results, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
service := hprose.NewHttpService()
|
// Create WebSocketServer
|
||||||
|
// service := rpc.NewWebSocketService()
|
||||||
|
|
||||||
|
// Create Http Server
|
||||||
|
service := rpc.NewHTTPService()
|
||||||
|
|
||||||
|
// Use Logger Middleware
|
||||||
|
service.AddInvokeHandler(logInvokeHandler)
|
||||||
|
|
||||||
|
// Publish Functions
|
||||||
service.AddFunction("AddOne", models.AddOne)
|
service.AddFunction("AddOne", models.AddOne)
|
||||||
service.AddFunction("GetOne", models.GetOne)
|
service.AddFunction("GetOne", models.GetOne)
|
||||||
|
|
||||||
|
// Start Service
|
||||||
beego.Handler("/", service)
|
beego.Handler("/", service)
|
||||||
beego.Run()
|
beego.Run()
|
||||||
}
|
}
|
||||||
@ -81,8 +106,11 @@ func main() {
|
|||||||
var hproseMainconngo = `package main
|
var hproseMainconngo = `package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
"{{.Appname}}/models"
|
"{{.Appname}}/models"
|
||||||
"github.com/hprose/hprose-go/hprose"
|
"github.com/hprose/hprose-golang/rpc"
|
||||||
|
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
"github.com/astaxie/beego/orm"
|
"github.com/astaxie/beego/orm"
|
||||||
@ -93,9 +121,30 @@ func init() {
|
|||||||
orm.RegisterDataBase("default", "{{.DriverName}}", "{{.conn}}")
|
orm.RegisterDataBase("default", "{{.DriverName}}", "{{.conn}}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func logInvokeHandler(
|
||||||
|
name string,
|
||||||
|
args []reflect.Value,
|
||||||
|
context rpc.Context,
|
||||||
|
next rpc.NextInvokeHandler) (results []reflect.Value, err error) {
|
||||||
|
fmt.Printf("%s(%v) = ", name, args)
|
||||||
|
results, err = next(name, args, context)
|
||||||
|
fmt.Printf("%v %v\r\n", results, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
service := hprose.NewHttpService()
|
// Create WebSocketServer
|
||||||
|
// service := rpc.NewWebSocketService()
|
||||||
|
|
||||||
|
// Create Http Server
|
||||||
|
service := rpc.NewHTTPService()
|
||||||
|
|
||||||
|
// Use Logger Middleware
|
||||||
|
service.AddInvokeHandler(logInvokeHandler)
|
||||||
|
|
||||||
{{HproseFunctionList}}
|
{{HproseFunctionList}}
|
||||||
|
|
||||||
|
// Start Service
|
||||||
beego.Handler("/", service)
|
beego.Handler("/", service)
|
||||||
beego.Run()
|
beego.Run()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user