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