-
Notifications
You must be signed in to change notification settings - Fork 63
/
main.go
43 lines (38 loc) · 982 Bytes
/
main.go
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
42
43
package main
import (
"fmt"
"log"
"net/http"
"os"
"github.com/metaparticle-io/package/go/metaparticle"
)
var port int32 = 8080
func handler(w http.ResponseWriter, r *http.Request) {
hostname, _ := os.Hostname()
fmt.Fprintf(w, "Hello metaparticle from %s %s!\n", r.RequestURI, hostname)
fmt.Printf("Request received: %s\n", r.RequestURI)
}
func main() {
metaparticle.Containerize(
&metaparticle.Runtime{
Ports: []int32{port},
Executor: "metaparticle",
Shards: 3,
URLShardPattern: "^\\/users\\/([^\\/]*)\\/.*",
},
&metaparticle.Package{
Name: "metaparticle-shard-demo",
Repository: "docker.io/brendanburns",
Builder: "docker",
Verbose: true,
Publish: true,
},
func() {
log.Printf("Starting server on :%d\n", port)
http.HandleFunc("/", handler)
err := http.ListenAndServe(fmt.Sprintf(":%d", port), nil)
if err != nil {
log.Fatal("Couldn't start the server: ", err)
}
})
}