This repository has been archived by the owner on Jun 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.go
63 lines (49 loc) · 1.51 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"flag"
"github.com/gin-gonic/gin"
"github.com/intervention-engine/fhir/server"
_ "github.com/synthetichealth/gofhir/synthma"
)
func main() {
// set up the commandline flags (-mongo and -pgurl)
reqLog := flag.Bool("reqlog", false, "Enables request logging -- do NOT use in production")
serverURL := flag.String("server", "", "The full URL for the root of the server")
dbName := flag.String("dbname", "fhir", "Mongo database name")
idxConfigPath := flag.String("idxconfig", "config/indexes.conf", "Path to the indexes config file")
mongoHost := flag.String("mongohost", "localhost", "the hostname of the mongo database")
readOnly := flag.Bool("readonly", false, "Run the API in read-only mode (no creates, updates, or deletes allowed)")
flag.Parse()
// setup the server
s := server.NewServer(*mongoHost)
config := server.DefaultConfig
if *serverURL != "" {
config.ServerURL = *serverURL
}
if *dbName != "" {
config.DatabaseName = *dbName
}
if *idxConfigPath != "" {
config.IndexConfigPath = *idxConfigPath
}
if *reqLog {
s.Engine.Use(server.RequestLoggerHandler)
}
if *readOnly {
s.Engine.Use(ReadOnlyHandler)
}
s.Run(config)
}
// ReadOnlyHandler makes the API read-only and responds to any requests that are not
// GET, HEAD, or OPTIONS with a 403 Forbidden error.
func ReadOnlyHandler(c *gin.Context) {
method := c.Request.Method
switch method {
// allowed methods:
case "GET", "HEAD", "OPTIONS":
return
// all other methods:
default:
c.AbortWithStatus(403)
}
}