Rename api package to http
This commit is contained in:
parent
f69ed83de7
commit
09acb111a2
@ -13,7 +13,7 @@
|
||||
staticProxyURL = "http://127.0.0.1:4002";
|
||||
|
||||
# password is "bar". This should definitely be changed for prod.
|
||||
apiAuthUsers = {
|
||||
httpAuthUsers = {
|
||||
"foo" = "$2a$13$0JdWlUfHc.3XimEMpEu1cuu6RodhUvzD9l7iiAqa4YkM3mcFV5Pxi";
|
||||
};
|
||||
}
|
||||
|
@ -34,7 +34,7 @@
|
||||
export MEDIOCRE_BLOG_LISTEN_ADDR="${config.listenAddr}"
|
||||
|
||||
# api
|
||||
export MEDIOCRE_BLOG_API_AUTH_USERS='${builtins.toJSON config.apiAuthUsers}'
|
||||
export MEDIOCRE_BLOG_API_AUTH_USERS='${builtins.toJSON config.httpAuthUsers}'
|
||||
'';
|
||||
|
||||
build = buildGoModule {
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/api"
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/http"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -19,5 +19,5 @@ func main() {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(api.NewPasswordHash(strings.TrimSpace(line)))
|
||||
fmt.Println(http.NewPasswordHash(strings.TrimSpace(line)))
|
||||
}
|
||||
|
@ -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
|
||||
apiParams.SetupCfg(cfg)
|
||||
ctx = mctx.WithAnnotator(ctx, &apiParams)
|
||||
var httpParams http.Params
|
||||
httpParams.SetupCfg(cfg)
|
||||
ctx = mctx.WithAnnotator(ctx, &httpParams)
|
||||
|
||||
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")
|
||||
|
||||
apiAuthUsersStr := 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")
|
||||
httpAuthUsersStr := 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 apiAuthUsers map[string]string
|
||||
if err := json.Unmarshal([]byte(*apiAuthUsersStr), &apiAuthUsers); err != nil {
|
||||
logger.Fatal(ctx, "unmarshaling -api-auth-users", err)
|
||||
var httpAuthUsers map[string]string
|
||||
if err := json.Unmarshal([]byte(*httpAuthUsersStr), &httpAuthUsers); err != nil {
|
||||
logger.Fatal(ctx, "unmarshaling -http-auth-users", err)
|
||||
}
|
||||
|
||||
apiParams.Logger = logger.WithNamespace("api")
|
||||
apiParams.PowManager = powMgr
|
||||
apiParams.PathPrefix = *pathPrefix
|
||||
apiParams.PostStore = postStore
|
||||
apiParams.PostAssetStore = postAssetStore
|
||||
apiParams.MailingList = ml
|
||||
apiParams.GlobalRoom = chatGlobalRoom
|
||||
apiParams.UserIDCalculator = chatUserIDCalc
|
||||
apiParams.AuthUsers = apiAuthUsers
|
||||
httpParams.Logger = logger.WithNamespace("http")
|
||||
httpParams.PowManager = powMgr
|
||||
httpParams.PathPrefix = *pathPrefix
|
||||
httpParams.PostStore = postStore
|
||||
httpParams.PostAssetStore = postAssetStore
|
||||
httpParams.MailingList = ml
|
||||
httpParams.GlobalRoom = chatGlobalRoom
|
||||
httpParams.UserIDCalculator = chatUserIDCalc
|
||||
httpParams.AuthUsers = httpAuthUsers
|
||||
|
||||
logger.Info(ctx, "listening")
|
||||
a, err := api.New(apiParams)
|
||||
httpAPI, err := http.New(httpParams)
|
||||
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)
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Package api implements the HTTP-based api for the mediocre-blog.
|
||||
package api
|
||||
package http
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -12,9 +12,9 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/api/apiutil"
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/cfg"
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/chat"
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/http/apiutil"
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/mailinglist"
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/post"
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/pow"
|
@ -1,4 +1,4 @@
|
||||
package api
|
||||
package http
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@ -12,7 +12,7 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/api/apiutil"
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/http/apiutil"
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/post"
|
||||
"golang.org/x/image/draw"
|
||||
)
|
@ -1,9 +1,9 @@
|
||||
package api
|
||||
package http
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/api/apiutil"
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/http/apiutil"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
@ -1,4 +1,4 @@
|
||||
package api
|
||||
package http
|
||||
|
||||
import (
|
||||
"testing"
|
@ -1,4 +1,4 @@
|
||||
package api
|
||||
package http
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -9,8 +9,8 @@ import (
|
||||
"unicode"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/api/apiutil"
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/chat"
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/http/apiutil"
|
||||
)
|
||||
|
||||
type chatHandler struct {
|
@ -1,10 +1,10 @@
|
||||
package api
|
||||
package http
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/api/apiutil"
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/http/apiutil"
|
||||
)
|
||||
|
||||
const (
|
@ -1,4 +1,4 @@
|
||||
package api
|
||||
package http
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -6,7 +6,7 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/api/apiutil"
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/http/apiutil"
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/post"
|
||||
)
|
||||
|
@ -1,11 +1,11 @@
|
||||
package api
|
||||
package http
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/api/apiutil"
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/http/apiutil"
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/mailinglist"
|
||||
)
|
||||
|
@ -1,11 +1,11 @@
|
||||
package api
|
||||
package http
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/api/apiutil"
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/http/apiutil"
|
||||
"github.com/mediocregopher/mediocre-go-lib/v2/mctx"
|
||||
"github.com/mediocregopher/mediocre-go-lib/v2/mlog"
|
||||
)
|
@ -1,4 +1,4 @@
|
||||
package api
|
||||
package http
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@ -12,7 +12,7 @@ import (
|
||||
"github.com/gomarkdown/markdown"
|
||||
"github.com/gomarkdown/markdown/html"
|
||||
"github.com/gomarkdown/markdown/parser"
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/api/apiutil"
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/http/apiutil"
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/post"
|
||||
)
|
||||
|
@ -1,4 +1,4 @@
|
||||
package api
|
||||
package http
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
@ -6,7 +6,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/api/apiutil"
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/http/apiutil"
|
||||
)
|
||||
|
||||
func (a *api) newPowChallengeHandler() http.Handler {
|
@ -1,4 +1,4 @@
|
||||
package api
|
||||
package http
|
||||
|
||||
import (
|
||||
"embed"
|
||||
@ -10,7 +10,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/api/apiutil"
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/http/apiutil"
|
||||
)
|
||||
|
||||
//go:embed tpl
|
Loading…
Reference in New Issue
Block a user