Rename api package to http

main
Brian Picciano 2 years ago
parent f69ed83de7
commit 09acb111a2
  1. 2
      config.nix
  2. 2
      srv/default.nix
  3. 4
      srv/src/cmd/hash-password/main.go
  4. 42
      srv/src/cmd/mediocre-blog/main.go
  5. 4
      srv/src/http/api.go
  6. 0
      srv/src/http/apiutil/apiutil.go
  7. 4
      srv/src/http/assets.go
  8. 4
      srv/src/http/auth.go
  9. 2
      srv/src/http/auth_test.go
  10. 4
      srv/src/http/chat.go
  11. 4
      srv/src/http/csrf.go
  12. 4
      srv/src/http/index.go
  13. 4
      srv/src/http/mailinglist.go
  14. 4
      srv/src/http/middleware.go
  15. 4
      srv/src/http/posts.go
  16. 4
      srv/src/http/pow.go
  17. 4
      srv/src/http/tpl.go
  18. 0
      srv/src/http/tpl/assets.html
  19. 0
      srv/src/http/tpl/base.html
  20. 0
      srv/src/http/tpl/edit-post.html
  21. 0
      srv/src/http/tpl/follow.html
  22. 0
      srv/src/http/tpl/index.html
  23. 0
      srv/src/http/tpl/post.html
  24. 0
      srv/src/http/tpl/posts.html
  25. 0
      srv/src/http/tpl/redirect.html

@ -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…
Cancel
Save