@ -8,9 +8,9 @@ import (
"syscall"
"time"
"github.com/mediocregopher/blog.mediocregopher.com/srv/api"
cfgpkg "github.com/mediocregopher/blog.mediocregopher.com/srv/cfg"
"github.com/mediocregopher/blog.mediocregopher.com/srv/chat"
"github.com/mediocregopher/blog.mediocregopher.com/srv/http"
"github.com/mediocregopher/blog.mediocregopher.com/srv/mailinglist"
"github.com/mediocregopher/blog.mediocregopher.com/srv/post"
"github.com/mediocregopher/blog.mediocregopher.com/srv/pow"
@ -42,9 +42,9 @@ func main() {
mlParams . SetupCfg ( cfg )
ctx = mctx . WithAnnotator ( ctx , & mlParams )
var apiParams api . Params
api Params. SetupCfg ( cfg )
ctx = mctx . WithAnnotator ( ctx , & api Params)
var httpParams http . Params
http Params. SetupCfg ( cfg )
ctx = mctx . WithAnnotator ( ctx , & http Params)
var radixClient cfgpkg . RadixClient
radixClient . SetupCfg ( cfg )
@ -56,7 +56,7 @@ func main() {
pathPrefix := cfg . String ( "path-prefix" , "" , "Prefix which is optionally applied to all URL paths rendered by the blog" )
api AuthUsersStr := cfg . String ( "api -auth-users" , "{}" , "JSON object with usernames as values and password hashes (produced by the hash-password binary) as values. Denotes users which are able to edit server-side data" )
http AuthUsersStr := cfg . String ( "http -auth-users" , "{}" , "JSON object with usernames as values and password hashes (produced by the hash-password binary) as values. Denotes users which are able to edit server-side data" )
// initialization
err := cfg . Init ( ctx )
@ -131,32 +131,32 @@ func main() {
postStore := post . NewStore ( postSQLDB )
postAssetStore := post . NewAssetStore ( postSQLDB )
var api AuthUsers map [ string ] string
if err := json . Unmarshal ( [ ] byte ( * api AuthUsersStr) , & api AuthUsers) ; err != nil {
logger . Fatal ( ctx , "unmarshaling -api -auth-users" , err )
var http AuthUsers map [ string ] string
if err := json . Unmarshal ( [ ] byte ( * http AuthUsersStr) , & http AuthUsers) ; err != nil {
logger . Fatal ( ctx , "unmarshaling -http -auth-users" , err )
}
api Params. Logger = logger . WithNamespace ( "api " )
api Params. PowManager = powMgr
api Params. PathPrefix = * pathPrefix
api Params. PostStore = postStore
api Params. PostAssetStore = postAssetStore
api Params. MailingList = ml
api Params. GlobalRoom = chatGlobalRoom
api Params. UserIDCalculator = chatUserIDCalc
api Params. AuthUsers = api AuthUsers
http Params. Logger = logger . WithNamespace ( "http " )
http Params. PowManager = powMgr
http Params. PathPrefix = * pathPrefix
http Params. PostStore = postStore
http Params. PostAssetStore = postAssetStore
http Params. MailingList = ml
http Params. GlobalRoom = chatGlobalRoom
http Params. UserIDCalculator = chatUserIDCalc
http Params. AuthUsers = http AuthUsers
logger . Info ( ctx , "listening" )
a , err := api . New ( api Params)
httpAPI , err := http . New ( http Params)
if err != nil {
logger . Fatal ( ctx , "initializing api" , err )
logger . Fatal ( ctx , "initializing http api" , err )
}
defer func ( ) {
shutdownCtx , cancel := context . WithTimeout ( ctx , 5 * time . Second )
defer cancel ( )
if err := a . Shutdown ( shutdownCtx ) ; err != nil {
logger . Fatal ( ctx , "shutting down api" , err )
if err := httpAPI . Shutdown ( shutdownCtx ) ; err != nil {
logger . Fatal ( ctx , "shutting down http api" , err )
}
} ( )