Skip to content

Commit 375b38d

Browse files
committed
first commit
0 parents  commit 375b38d

File tree

8 files changed

+118
-0
lines changed

8 files changed

+118
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
go/pkg
2+
go/src/github.com
3+
go/src/client/client
4+
go/src/service/service
5+
6+
nodejs/client/node_modules
7+
nodejs/service/node_modules

go/src/client/main.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
hprose "github.com/hprose/hprose-go"
7+
)
8+
9+
type Client struct {
10+
Say func(string)
11+
Hello func() string
12+
}
13+
14+
func main() {
15+
client := hprose.NewClient("http://127.0.0.1:7080")
16+
17+
c := &Client{}
18+
19+
client.UseService(c)
20+
21+
c.Say("world")
22+
fmt.Println(c.Hello())
23+
}

go/src/service/main.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
7+
hprose "github.com/hprose/hprose-go"
8+
)
9+
10+
type Person struct {
11+
Content string
12+
}
13+
14+
func (p *Person) Say(content string) {
15+
p.Content = content
16+
}
17+
18+
func (p *Person) Hello() string {
19+
return "Hello " + p.Content + "!"
20+
}
21+
22+
func main() {
23+
service := hprose.NewHttpService()
24+
25+
service.AddMethods(&Person{})
26+
27+
if err := http.ListenAndServe(":7080", service); err != nil {
28+
fmt.Println(err)
29+
return
30+
}
31+
}

nodejs/client/app.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
(function(){
2+
'use strict'
3+
4+
var hprose = require('hprose');
5+
6+
var client = hprose.Client.create('http://127.0.0.1:7080');
7+
8+
var person = client.useService(['Say', 'Hello']);
9+
person.Say('world', function(){});
10+
11+
person.Hello(function(content){
12+
console.log(content);
13+
});
14+
})();

nodejs/client/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "hprose",
3+
"version": "0.0.0",
4+
"private": true,
5+
"dependencies": {
6+
"hprose": "~1.6.4"
7+
}
8+
}

nodejs/service/app.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(function(){
2+
'use strict'
3+
4+
var hprose = require("hprose");
5+
var Person = require("./person");
6+
7+
var service = hprose.Server.create('http://127.0.0.1:7080');
8+
service.addInstanceMethods(Person);
9+
service.start();
10+
})();

nodejs/service/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "hprose",
3+
"version": "0.0.0",
4+
"private": true,
5+
"dependencies": {
6+
"hprose": "~1.6.4"
7+
}
8+
}

nodejs/service/person.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
(function(){
2+
'use strict'
3+
4+
var Person = {
5+
content: ''
6+
};
7+
8+
Person.Say = function(content){
9+
this.content = content;
10+
}
11+
12+
Person.Hello = function(){
13+
return 'Hello ' + this.content + '!';
14+
}
15+
16+
module.exports = Person;
17+
})();

0 commit comments

Comments
 (0)