working local dev config
This commit is contained in:
@@ -3,3 +3,4 @@
|
||||
target
|
||||
/logs/
|
||||
/target/
|
||||
/var/
|
||||
+3
-3
@@ -9,18 +9,18 @@ RUN gometalinter --disable-all --deadline=300s --vendor --enable=vet --enable=ve
|
||||
--enable=staticcheck --enable=ineffassign --enable=goconst --enable=errcheck --enable=unconvert \
|
||||
--enable=deadcode --enable=gosimple --enable=gas --exclude=test ./...
|
||||
|
||||
RUN /script/checkvendor.sh
|
||||
#RUN /script/checkvendor.sh
|
||||
RUN mkdir -p target && /script/coverage.sh
|
||||
|
||||
RUN go build -o remark -ldflags "-X main.revision=$(git rev-parse --abbrev-ref HEAD)-$(git describe --abbrev=7 --always --tags)-$(date +%Y%m%d-%H:%M:%S)" ./app
|
||||
|
||||
# Run
|
||||
|
||||
FROM umputun/baseimage:micro-latest
|
||||
|
||||
RUN apk add --update ca-certificates && update-ca-certificates
|
||||
|
||||
COPY --from=build /go/src/github.com/umputun/remark/remark /srv/
|
||||
|
||||
COPY --from=build /go/src/github.com/umputun/remark/web /srv/web
|
||||
RUN chown -R umputun:umputun /srv
|
||||
|
||||
USER umputun
|
||||
|
||||
@@ -140,8 +140,8 @@ func (p Provider) AuthHandler(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("[DEBUG] %+v", jData)
|
||||
|
||||
// redirect to back url if presented
|
||||
if fromUrl, ok := session.Values["from"]; ok {
|
||||
http.Redirect(w, r, fromUrl.(string), http.StatusTemporaryRedirect)
|
||||
if fromURL, ok := session.Values["from"]; ok {
|
||||
http.Redirect(w, r, fromURL.(string), http.StatusTemporaryRedirect)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -4,12 +4,11 @@ import (
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"path/filepath"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/go-chi/chi/middleware"
|
||||
"github.com/go-chi/render"
|
||||
|
||||
+8
-7
@@ -39,7 +39,7 @@ func (b *BoltDB) Create(comment Comment) (int64, error) {
|
||||
|
||||
comment.ID = time.Now().UnixNano()
|
||||
comment.Timestamp = time.Now()
|
||||
comment.Votes = map[string]bool{}
|
||||
comment.Votes = make(map[string]bool)
|
||||
|
||||
err := b.Update(func(tx *bolt.Tx) error {
|
||||
bucket, e := tx.CreateBucketIfNotExists([]byte(comment.Locator.URL))
|
||||
@@ -197,7 +197,7 @@ func (b *BoltDB) Last(locator Locator, max int) (result []Comment, err error) {
|
||||
return result, err
|
||||
}
|
||||
|
||||
// Get comment by id
|
||||
// Vote for comment by id and locator
|
||||
func (b *BoltDB) Vote(locator Locator, commentID int64, userID string, val bool) (comment Comment, err error) {
|
||||
|
||||
err = b.Update(func(tx *bolt.Tx) error {
|
||||
@@ -230,12 +230,12 @@ func (b *BoltDB) Vote(locator Locator, commentID int64, userID string, val bool)
|
||||
} else {
|
||||
comment.Score--
|
||||
}
|
||||
data, err := json.Marshal(&comment)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "can't marshal comment with updated votes")
|
||||
data, e := json.Marshal(&comment)
|
||||
if e != nil {
|
||||
return errors.Wrap(e, "can't marshal comment with updated votes")
|
||||
}
|
||||
if err = bucket.Put(b.keyFromValue(commentID), data); err != nil {
|
||||
return errors.Wrap(err, "failed to save comment with updated votes")
|
||||
if e = bucket.Put(b.keyFromValue(commentID), data); e != nil {
|
||||
return errors.Wrap(e, "failed to save comment with updated votes")
|
||||
}
|
||||
return nil
|
||||
})
|
||||
@@ -243,6 +243,7 @@ func (b *BoltDB) Vote(locator Locator, commentID int64, userID string, val bool)
|
||||
return comment, err
|
||||
}
|
||||
|
||||
// Count returns number of comments for locator
|
||||
func (b *BoltDB) Count(locator Locator) (count int, err error) {
|
||||
err = b.View(func(tx *bolt.Tx) error {
|
||||
bucket := tx.Bucket([]byte(locator.URL))
|
||||
|
||||
@@ -76,6 +76,7 @@ func TestBoltDB_Vote(t *testing.T) {
|
||||
b := prep(t)
|
||||
|
||||
res, err := b.Last(Locator{URL: "https://radio-t.com"}, 0)
|
||||
t.Logf("%+v", res[0])
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 2, len(res))
|
||||
assert.Equal(t, 0, res[0].Score)
|
||||
@@ -106,6 +107,8 @@ func TestBoltDB_Count(t *testing.T) {
|
||||
|
||||
// makes new boltdb, put two records
|
||||
func prep(t *testing.T) *BoltDB {
|
||||
os.Remove(testDb)
|
||||
|
||||
b, err := NewBoltDB(testDb)
|
||||
assert.Nil(t, err)
|
||||
|
||||
|
||||
+3
-3
@@ -10,8 +10,8 @@ type Comment struct {
|
||||
User User `json:"user"`
|
||||
Locator Locator `json:"locator"`
|
||||
Score int `json:"score"`
|
||||
Votes map[string]bool `json:"votes,omitempty"`
|
||||
Timestamp time.Time `json:"time,omitempty"`
|
||||
Votes map[string]bool `json:"votes"`
|
||||
Timestamp time.Time `json:"time"`
|
||||
}
|
||||
|
||||
// Locator keeps site and url of the post
|
||||
@@ -26,7 +26,7 @@ type User struct {
|
||||
ID string `json:"id"`
|
||||
Picture string `json:"picture"`
|
||||
Profile string `json:"profile"`
|
||||
Admin bool `json:"admin,omitempty"`
|
||||
Admin bool `json:"admin"`
|
||||
IP string `json:"-"`
|
||||
}
|
||||
|
||||
|
||||
@@ -18,3 +18,15 @@ services:
|
||||
environment:
|
||||
- MHOST=${MHOST}
|
||||
|
||||
ports:
|
||||
- "8080:8080"
|
||||
|
||||
environment:
|
||||
- BOLTDB_FILE=/srv/var/remark.db
|
||||
- SESSION_STORE=/srv/var
|
||||
- DEV=true
|
||||
- DEBUG=true
|
||||
|
||||
volumes:
|
||||
- ./var:/srv/var
|
||||
|
||||
|
||||
Reference in New Issue
Block a user