Skip to content

Commit

Permalink
Renamed module
Browse files Browse the repository at this point in the history
  • Loading branch information
CristianUser committed May 21, 2023
1 parent 778434b commit 55a249f
Show file tree
Hide file tree
Showing 22 changed files with 86 additions and 49 deletions.
37 changes: 37 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM golang:1.20 AS builder

COPY ../ /app
WORKDIR /app
RUN ls
# Toggle CGO on your app requirement
RUN CGO_ENABLED=0 go build -ldflags '-s -w -extldflags "-static"' -o /app/appbin main.go
# Use below if using vendor
# RUN CGO_ENABLED=0 go build -mod=vendor -ldflags '-extldflags "-static"' -o /app/appbin *.go

FROM debian:stable-slim
LABEL MAINTAINER Author <author@example.com>

# Following commands are for installing CA certs (for proper functioning of HTTPS and other TLS)
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
netbase \
&& rm -rf /var/lib/apt/lists/ \
&& apt-get autoremove -y && apt-get autoclean -y

# Add new user 'appuser'. App should be run without root privileges as a security measure
RUN adduser --home "/appuser" --disabled-password appuser \
--gecos "appuser,-,-,-"
USER appuser

COPY --from=builder /app/internal/server/http/web /home/appuser/app/web
COPY --from=builder /app/appbin /home/appuser/app

ENV TEMPLATES_BASEPATH=/home/appuser/app/web/templates

WORKDIR /home/appuser/app

# Since running as a non-root user, port bindings < 1024 are not possible
# 8000 for HTTP; 8443 for HTTPS;
EXPOSE 8000

CMD ["./appbin"]
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Go treemux + bun realworld application
# Go bunrouter + bun application example

[![build workflow](https://github.com/go-bun/bun-realworld-app/actions/workflows/build.yml/badge.svg)](https://github.com/go-bun/bun-realworld-app/actions)
[![PkgGoDev](https://pkg.go.dev/badge/github.com/uptrace/bun-realworld-app)](https://pkg.go.dev/github.com/uptrace/bun-realworld-app)
[![PkgGoDev](https://pkg.go.dev/badge/github.com/cristianuser/go-bun-webserver)](https://pkg.go.dev/github.com/cristianuser/go-bun-webserver)

## Introduction

This project implements RealWorld JSON API as specified in the
[spec](https://github.com/gothinkster/realworld). It was created to demonstrate how to use:

- [treemux HTTP router](https://github.com/vmihailenco/treemux).
- [Bun Router](https://github.com/uptrace/bunrouter).
- [Bun DB](https://github.com/uptrace/bun).
- [bun/migrate](https://bun.uptrace.dev/guide/migrations.html).
- [bun/dbfixture](https://bun.uptrace.dev/guide/fixtures.html).
Expand Down
4 changes: 2 additions & 2 deletions blog/article.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"context"
"time"

"github.com/cristianuser/go-bun-webserver/bunapp"
"github.com/cristianuser/go-bun-webserver/org"
"github.com/uptrace/bun"
"github.com/uptrace/bun-realworld-app/bunapp"
"github.com/uptrace/bun-realworld-app/org"
)

type Article struct {
Expand Down
4 changes: 2 additions & 2 deletions blog/article_filter.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package blog

import (
"github.com/cristianuser/go-bun-webserver/bunapp"
"github.com/cristianuser/go-bun-webserver/org"
"github.com/go-pg/urlstruct"
"github.com/uptrace/bun"
"github.com/uptrace/bun-realworld-app/bunapp"
"github.com/uptrace/bun-realworld-app/org"
"github.com/uptrace/bunrouter"
)

Expand Down
6 changes: 3 additions & 3 deletions blog/article_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"net/http"
"strconv"

"github.com/uptrace/bun-realworld-app/bunapp"
"github.com/uptrace/bun-realworld-app/httputil"
"github.com/uptrace/bun-realworld-app/org"
"github.com/cristianuser/go-bun-webserver/bunapp"
"github.com/cristianuser/go-bun-webserver/httputil"
"github.com/cristianuser/go-bun-webserver/org"
"github.com/uptrace/bunrouter"

"github.com/gosimple/slug"
Expand Down
4 changes: 2 additions & 2 deletions blog/blog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"testing"
"time"

"github.com/uptrace/bun-realworld-app/org"
"github.com/uptrace/bun-realworld-app/testbed"
"github.com/cristianuser/go-bun-webserver/org"
"github.com/cristianuser/go-bun-webserver/testbed"
"github.com/uptrace/bun/dbfixture"

. "github.com/onsi/ginkgo"
Expand Down
2 changes: 1 addition & 1 deletion blog/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package blog
import (
"time"

"github.com/cristianuser/go-bun-webserver/org"
"github.com/uptrace/bun"
"github.com/uptrace/bun-realworld-app/org"
)

type Comment struct {
Expand Down
6 changes: 3 additions & 3 deletions blog/comment_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"errors"
"net/http"

"github.com/uptrace/bun-realworld-app/bunapp"
"github.com/uptrace/bun-realworld-app/httputil"
"github.com/uptrace/bun-realworld-app/org"
"github.com/cristianuser/go-bun-webserver/bunapp"
"github.com/cristianuser/go-bun-webserver/httputil"
"github.com/cristianuser/go-bun-webserver/org"
"github.com/uptrace/bunrouter"
)

Expand Down
4 changes: 2 additions & 2 deletions blog/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package blog
import (
"context"

"github.com/uptrace/bun-realworld-app/bunapp"
"github.com/uptrace/bun-realworld-app/org"
"github.com/cristianuser/go-bun-webserver/bunapp"
"github.com/cristianuser/go-bun-webserver/org"
)

func init() {
Expand Down
2 changes: 1 addition & 1 deletion blog/tag_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"database/sql"
"net/http"

"github.com/uptrace/bun-realworld-app/bunapp"
"github.com/cristianuser/go-bun-webserver/bunapp"
"github.com/uptrace/bunrouter"
)

Expand Down
2 changes: 1 addition & 1 deletion bunapp/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package bunapp
import (
"net/http"

"github.com/uptrace/bun-realworld-app/httputil/httperror"
"github.com/cristianuser/go-bun-webserver/httputil/httperror"
"github.com/uptrace/bunrouter"
"github.com/uptrace/bunrouter/extra/bunrouterotel"
"github.com/uptrace/bunrouter/extra/reqlog"
Expand Down
10 changes: 5 additions & 5 deletions cmd/bun/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
"strings"
"time"

_ "github.com/uptrace/bun-realworld-app/blog"
"github.com/uptrace/bun-realworld-app/bunapp"
"github.com/uptrace/bun-realworld-app/cmd/bun/migrations"
"github.com/uptrace/bun-realworld-app/httputil"
_ "github.com/uptrace/bun-realworld-app/org"
_ "github.com/cristianuser/go-bun-webserver/blog"
"github.com/cristianuser/go-bun-webserver/bunapp"
"github.com/cristianuser/go-bun-webserver/cmd/bun/migrations"
"github.com/cristianuser/go-bun-webserver/httputil"
_ "github.com/cristianuser/go-bun-webserver/org"
"github.com/uptrace/bun/migrate"
"github.com/urfave/cli/v2"
)
Expand Down
4 changes: 2 additions & 2 deletions cmd/bun/migrations/20230521152050_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"context"
"fmt"

"github.com/cristianuser/go-bun-webserver/bunapp"
"github.com/cristianuser/go-bun-webserver/org"
"github.com/uptrace/bun"
"github.com/uptrace/bun-realworld-app/bunapp"
"github.com/uptrace/bun-realworld-app/org"
"github.com/uptrace/bun/dbfixture"
)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/uptrace/bun-realworld-app
module github.com/cristianuser/go-bun-webserver

go 1.16

Expand Down
20 changes: 10 additions & 10 deletions httputil/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ func JSON(w http.ResponseWriter, value interface{}, s int) error {
return nil
}

// func BindJSON(
// w http.ResponseWriter,
// req bunrouter.Request,
// dst interface{},
// ) error {
// if err := UnmarshalJSON(w, req, dst, 10); err != nil {
// return err
// }
// return Validate(w, dst)
// }
func BindJSON(
w http.ResponseWriter,
req bunrouter.Request,
dst interface{},
) error {
if err := UnmarshalJSON(w, req, dst, 10); err != nil {
return err
}
return nil
}
4 changes: 2 additions & 2 deletions org/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"net/http"
"strings"

"github.com/uptrace/bun-realworld-app/bunapp"
"github.com/uptrace/bun-realworld-app/httputil"
"github.com/cristianuser/go-bun-webserver/bunapp"
"github.com/cristianuser/go-bun-webserver/httputil"
"github.com/uptrace/bunrouter"
)

Expand Down
2 changes: 1 addition & 1 deletion org/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org
import (
"context"

"github.com/uptrace/bun-realworld-app/bunapp"
"github.com/cristianuser/go-bun-webserver/bunapp"
)

func init() {
Expand Down
4 changes: 2 additions & 2 deletions org/org_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"net/http/httptest"
"testing"

"github.com/uptrace/bun-realworld-app/org"
"github.com/uptrace/bun-realworld-app/testbed"
"github.com/cristianuser/go-bun-webserver/org"
"github.com/cristianuser/go-bun-webserver/testbed"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down
2 changes: 1 addition & 1 deletion org/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"strconv"
"time"

"github.com/cristianuser/go-bun-webserver/bunapp"
"github.com/dgrijalva/jwt-go"
"github.com/uptrace/bun-realworld-app/bunapp"
)

func decodeUserToken(app *bunapp.App, jwtToken string) (uint64, error) {
Expand Down
2 changes: 1 addition & 1 deletion org/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"errors"
"time"

"github.com/cristianuser/go-bun-webserver/bunapp"
"github.com/uptrace/bun"
"github.com/uptrace/bun-realworld-app/bunapp"
"golang.org/x/crypto/bcrypt"
)

Expand Down
4 changes: 2 additions & 2 deletions org/user_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"github.com/uptrace/bunrouter"
"golang.org/x/crypto/bcrypt"

"github.com/cristianuser/go-bun-webserver/bunapp"
"github.com/cristianuser/go-bun-webserver/httputil"
"github.com/uptrace/bun"
"github.com/uptrace/bun-realworld-app/bunapp"
"github.com/uptrace/bun-realworld-app/httputil"
)

const kb = 10
Expand Down
4 changes: 2 additions & 2 deletions testbed/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"time"

"github.com/benbjohnson/clock"
"github.com/uptrace/bun-realworld-app/bunapp"
"github.com/uptrace/bun-realworld-app/org"
"github.com/cristianuser/go-bun-webserver/bunapp"
"github.com/cristianuser/go-bun-webserver/org"
)

type TestApp struct {
Expand Down

0 comments on commit 55a249f

Please sign in to comment.