-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample_interface_test.go
More file actions
41 lines (31 loc) · 956 Bytes
/
Copy pathexample_interface_test.go
File metadata and controls
41 lines (31 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package gotojs
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"time"
)
// Declare Service to be exposed.
type Service struct {
name string
}
// Methods of Service that will be exposed.
func (s *Service) Hello(name string) string {
return fmt.Sprintf("Hello %s, how are you ? Regards, %s.", name, s.name)
}
func ExampleContainer_interface() {
// Initialize the container.
container := NewContainer()
service := Service{name: "TestService"}
// Expose the funcation and name it.
container.ExposeInterface(service)
// Start the server is seperate go routine in parallel.
go func() { log.Fatal(container.Start("localhost:8790")) }()
time.Sleep(1 * time.Second) // Wait for the other go routine having the server up and running.
resp, _ := http.Get("http://localhost:8790/gotojs/Service/Hello/TestEngine")
b, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(b))
// Output:
// "Hello TestEngine, how are you ? Regards, TestService."
}