summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Picciano <mediocregopher@gmail.com>2022-05-20 11:17:31 -0600
committerBrian Picciano <mediocregopher@gmail.com>2022-05-20 11:17:31 -0600
commit09acb111a2b22f5794541fac175b024dd0f9100e (patch)
tree11d4578a42ad4aea968b42a2689f64c799f9176e
parentf69ed83de73bbfc4b7af0931de6ced8cf12dea61 (diff)
Rename api package to http
-rw-r--r--config.nix2
-rw-r--r--srv/default.nix2
-rw-r--r--srv/src/cmd/hash-password/main.go4
-rw-r--r--srv/src/cmd/mediocre-blog/main.go42
-rw-r--r--srv/src/http/api.go (renamed from srv/src/api/api.go)4
-rw-r--r--srv/src/http/apiutil/apiutil.go (renamed from srv/src/api/apiutil/apiutil.go)0
-rw-r--r--srv/src/http/assets.go (renamed from srv/src/api/assets.go)4
-rw-r--r--srv/src/http/auth.go (renamed from srv/src/api/auth.go)4
-rw-r--r--srv/src/http/auth_test.go (renamed from srv/src/api/auth_test.go)2
-rw-r--r--srv/src/http/chat.go (renamed from srv/src/api/chat.go)4
-rw-r--r--srv/src/http/csrf.go (renamed from srv/src/api/csrf.go)4
-rw-r--r--srv/src/http/index.go (renamed from srv/src/api/index.go)4
-rw-r--r--srv/src/http/mailinglist.go (renamed from srv/src/api/mailinglist.go)4
-rw-r--r--srv/src/http/middleware.go (renamed from srv/src/api/middleware.go)4
-rw-r--r--srv/src/http/posts.go (renamed from srv/src/api/posts.go)4
-rw-r--r--srv/src/http/pow.go (renamed from srv/src/api/pow.go)4
-rw-r--r--srv/src/http/tpl.go (renamed from srv/src/api/tpl.go)4
-rw-r--r--srv/src/http/tpl/assets.html (renamed from srv/src/api/tpl/assets.html)0
-rw-r--r--srv/src/http/tpl/base.html (renamed from srv/src/api/tpl/base.html)0
-rw-r--r--srv/src/http/tpl/edit-post.html (renamed from srv/src/api/tpl/edit-post.html)0
-rw-r--r--srv/src/http/tpl/follow.html (renamed from srv/src/api/tpl/follow.html)0
-rw-r--r--srv/src/http/tpl/index.html (renamed from srv/src/api/tpl/index.html)0
-rw-r--r--srv/src/http/tpl/post.html (renamed from srv/src/api/tpl/post.html)0
-rw-r--r--srv/src/http/tpl/posts.html (renamed from srv/src/api/tpl/posts.html)0
-rw-r--r--srv/src/http/tpl/redirect.html (renamed from srv/src/api/tpl/redirect.html)0
25 files changed, 48 insertions, 48 deletions
diff --git a/config.nix b/config.nix
index 1e3726c..2aa8462 100644
--- a/config.nix
+++ b/config.nix
@@ -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";
};
}
diff --git a/srv/default.nix b/srv/default.nix
index e7286b6..a8f3464 100644
--- a/srv/default.nix
+++ b/srv/default.nix
@@ -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 {
diff --git a/srv/src/cmd/hash-password/main.go b/srv/src/cmd/hash-password/main.go
index b787a4d..47ae1e7 100644
--- a/srv/src/cmd/hash-password/main.go
+++ b/srv/src/cmd/hash-password/main.go
@@ -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)))
}
diff --git a/srv/src/cmd/mediocre-blog/main.go b/srv/src/cmd/mediocre-blog/main.go
index 5cb4d5f..f76188b 100644
--- a/srv/src/cmd/mediocre-blog/main.go
+++ b/srv/src/cmd/mediocre-blog/main.go
@@ -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)
}
}()
diff --git a/srv/src/api/api.go b/srv/src/http/api.go
index 191a7bf..bbf4419 100644
--- a/srv/src/api/api.go
+++ b/srv/src/http/api.go
@@ -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"
diff --git a/srv/src/api/apiutil/apiutil.go b/srv/src/http/apiutil/apiutil.go
index d427b65..d427b65 100644
--- a/srv/src/api/apiutil/apiutil.go
+++ b/srv/src/http/apiutil/apiutil.go
diff --git a/srv/src/api/assets.go b/srv/src/http/assets.go
index 47be14c..f782c69 100644
--- a/srv/src/api/assets.go
+++ b/srv/src/http/assets.go
@@ -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"
)
diff --git a/srv/src/api/auth.go b/srv/src/http/auth.go
index 0d946a3..cd247a3 100644
--- a/srv/src/api/auth.go
+++ b/srv/src/http/auth.go
@@ -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"
)
diff --git a/srv/src/api/auth_test.go b/srv/src/http/auth_test.go
index cdf83ef..2a1e6e9 100644
--- a/srv/src/api/auth_test.go
+++ b/srv/src/http/auth_test.go
@@ -1,4 +1,4 @@
-package api
+package http
import (
"testing"
diff --git a/srv/src/api/chat.go b/srv/src/http/chat.go
index f4b90ef..f76e4ad 100644
--- a/srv/src/api/chat.go
+++ b/srv/src/http/chat.go
@@ -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 {
diff --git a/srv/src/api/csrf.go b/srv/src/http/csrf.go
index 2a93ed7..1c80dee 100644
--- a/srv/src/api/csrf.go
+++ b/srv/src/http/csrf.go
@@ -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 (
diff --git a/srv/src/api/index.go b/srv/src/http/index.go
index 5fb5a4f..bb76568 100644
--- a/srv/src/api/index.go
+++ b/srv/src/http/index.go
@@ -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"
)
diff --git a/srv/src/api/mailinglist.go b/srv/src/http/mailinglist.go
index c12e75d..90e602c 100644
--- a/srv/src/api/mailinglist.go
+++ b/srv/src/http/mailinglist.go
@@ -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"
)
diff --git a/srv/src/api/middleware.go b/srv/src/http/middleware.go
index 974889b..8299a71 100644
--- a/srv/src/api/middleware.go
+++ b/srv/src/http/middleware.go
@@ -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"
)
diff --git a/srv/src/api/posts.go b/srv/src/http/posts.go
index ab11474..fd583ea 100644
--- a/srv/src/api/posts.go
+++ b/srv/src/http/posts.go
@@ -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"
)
diff --git a/srv/src/api/pow.go b/srv/src/http/pow.go
index ae2d2f1..1bd5cb5 100644
--- a/srv/src/api/pow.go
+++ b/srv/src/http/pow.go
@@ -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 {
diff --git a/srv/src/api/tpl.go b/srv/src/http/tpl.go
index 9818b10..d647317 100644
--- a/srv/src/api/tpl.go
+++ b/srv/src/http/tpl.go
@@ -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
diff --git a/srv/src/api/tpl/assets.html b/srv/src/http/tpl/assets.html
index aa5e422..aa5e422 100644
--- a/srv/src/api/tpl/assets.html
+++ b/srv/src/http/tpl/assets.html
diff --git a/srv/src/api/tpl/base.html b/srv/src/http/tpl/base.html
index 6031919..6031919 100644
--- a/srv/src/api/tpl/base.html
+++ b/srv/src/http/tpl/base.html
diff --git a/srv/src/api/tpl/edit-post.html b/srv/src/http/tpl/edit-post.html
index 9ccfa2a..9ccfa2a 100644
--- a/srv/src/api/tpl/edit-post.html
+++ b/srv/src/http/tpl/edit-post.html
diff --git a/srv/src/api/tpl/follow.html b/srv/src/http/tpl/follow.html
index 8cf9dc6..8cf9dc6 100644
--- a/srv/src/api/tpl/follow.html
+++ b/srv/src/http/tpl/follow.html
diff --git a/srv/src/api/tpl/index.html b/srv/src/http/tpl/index.html
index e27cbef..e27cbef 100644
--- a/srv/src/api/tpl/index.html
+++ b/srv/src/http/tpl/index.html
diff --git a/srv/src/api/tpl/post.html b/srv/src/http/tpl/post.html
index 474d7c2..474d7c2 100644
--- a/srv/src/api/tpl/post.html
+++ b/srv/src/http/tpl/post.html
diff --git a/srv/src/api/tpl/posts.html b/srv/src/http/tpl/posts.html
index 714cf07..714cf07 100644
--- a/srv/src/api/tpl/posts.html
+++ b/srv/src/http/tpl/posts.html
diff --git a/srv/src/api/tpl/redirect.html b/srv/src/http/tpl/redirect.html
index ed12a2e..ed12a2e 100644
--- a/srv/src/api/tpl/redirect.html
+++ b/srv/src/http/tpl/redirect.html