forked from Shyp/rickover
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample_server_test.go
51 lines (42 loc) · 1.31 KB
/
example_server_test.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
44
45
46
47
48
49
50
51
// Run the rickover server.
//
// All of the project defaults are used. There is one authenticated user for
// basic auth, the user is "test" and the password is "hymanrickover". You will
// want to copy this binary and add your own authentication scheme.
package rickover
import (
"context"
"log"
"net/http"
"time"
"github.com/kevinburke/handlers"
"github.com/kevinburke/rickover/config"
"github.com/kevinburke/rickover/metrics"
"github.com/kevinburke/rickover/models/db"
"github.com/kevinburke/rickover/server"
"github.com/kevinburke/rickover/setup"
)
var serverDbConns int
func init() {
var err error
serverDbConns, err = config.GetInt("PG_SERVER_POOL_SIZE")
if err != nil {
log.Printf("Error getting database pool size: %s. Defaulting to 10", err)
serverDbConns = 10
}
// Change this user to a private value
server.AddUser("test", "hymanrickover")
}
func Example_server() {
if err := setup.DB(context.TODO(), db.DefaultConnection, serverDbConns); err != nil {
log.Fatal(err)
}
go metrics.Run(context.TODO(), metrics.LibratoConfig{
Namespace: "rickover.server",
Source: "web",
Email: "[email protected]",
})
go setup.MeasureActiveQueries(context.TODO(), 5*time.Second)
log.Println("Listening on port 9090")
log.Fatal(http.ListenAndServe(":9090", handlers.Log(server.DefaultServer)))
}