Skip to content

Commit

Permalink
Docker and imports from git
Browse files Browse the repository at this point in the history
  • Loading branch information
HaseProgram committed Jan 12, 2018
1 parent 518b363 commit 87c0f6a
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 21 deletions.
46 changes: 46 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
FROM ubuntu:16.04

MAINTAINER Dmitry Zaytsev

RUN apt-get -y update && apt-get install -y wget git


ENV PGVER 10
RUN apt-get install -q -y postgresql-$PGVER

USER postgres

RUN /etc/init.d/postgresql start &&\
psql --command "CREATE USER postgres WITH SUPERUSER PASSWORD '126126';" &&\
createdb -O hasep dbproj &&\
/etc/init.d/postgresql stop


RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/$PGVER/main/pg_hba.conf
RUN echo "listen_addresses='*'" >> /etc/postgresql/$PGVER/main/postgresql.conf

RUN echo "autovacuum = off" >> /etc/postgresql/$PGVER/main/postgresql.conf
RUN echo "fsync = off" >> /etc/postgresql/$PGVER/main/postgresql.conf
RUN echo "full_page_writes = off" >> /etc/postgresql/$PGVER/main/postgresql.conf
RUN echo "synchronous_commit = off" >> /etc/postgresql/$PGVER/main/postgresql.conf

EXPOSE 5432
USER root

# INSTALL GO
apt-get install -q -y git golang-go

ENV GOPATH /go

RUN go get -u github.com/go-ozzo/ozzo-routing/...
RUN go get -u github.com/jackc/pgx/...


WORKDIR /go/src/github.com/HaseProgram/technoparkdb
ADD . $GOPATH/src/github.com/HaseProgram/technoparkdb

RUN go install github.com/HaseProgram/technoparkdb/

EXPOSE 5000

CMD /etc/init.d/postgresql start && ./dbproj
16 changes: 16 additions & 0 deletions database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package database
import (
"github.com/jackc/pgx"
"runtime"
"io/ioutil"
)

var DB *pgx.ConnPool
Expand All @@ -22,4 +23,19 @@ func Connect() {
if err != nil {
panic(err)
}
err = createShema()
if err != nil {
panic(err)
}
}

func createShema() error {
sql, err := ioutil.ReadFile("db.sql")
if err != nil {
return err
}
shema := string(sql)

_, err = DB.Exec(shema)
return err
}
1 change: 1 addition & 0 deletions db.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
SET SYNCHRONOUS_COMMIT = 'off';
CREATE EXTENSION IF NOT EXISTS CITEXT;

DROP TABLE forums;
DROP TABLE threads;
Expand Down
8 changes: 4 additions & 4 deletions forum/forum.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package forum
import (
"github.com/go-ozzo/ozzo-routing"
"encoding/json"
"technoparkdb/common"
"technoparkdb/user"
"technoparkdb/database"
"github.com/HaseProgram/technoparkdb/common"
"github.com/HaseProgram/technoparkdb/user"
"github.com/HaseProgram/technoparkdb/database"
"github.com/jackc/pgx"
"technoparkdb/thread"
"github.com/HaseProgram/technoparkdb/thread"
"time"
"fmt"
"sync"
Expand Down
2 changes: 1 addition & 1 deletion forum/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package forum

import (
"github.com/go-ozzo/ozzo-routing"
"technoparkdb/thread"
"github.com/HaseProgram/technoparkdb/thread"
)

func Route(router *routing.Router) {
Expand Down
14 changes: 7 additions & 7 deletions mian.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import (
"net/http"
"github.com/go-ozzo/ozzo-routing"
"github.com/go-ozzo/ozzo-routing/slash"
"technoparkdb/user"
"github.com/HaseProgram/technoparkdb/user"

"technoparkdb/forum"
"technoparkdb/thread"
"technoparkdb/database"
"technoparkdb/post"
"technoparkdb/service"
"github.com/HaseProgram/technoparkdb/forum"
"github.com/HaseProgram/technoparkdb/thread"
"github.com/HaseProgram/technoparkdb/database"
"github.com/HaseProgram/technoparkdb/post"
"github.com/HaseProgram/technoparkdb/service"
_ "net/http/pprof"
)

var router *routing.Router

func main() {
database.Connect()
defer database.DB.Close()
//defer database.DB.Close()
router := routing.New()
router.Use(
slash.Remover(http.StatusMovedPermanently),
Expand Down
9 changes: 6 additions & 3 deletions post/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package post
import (
"github.com/go-ozzo/ozzo-routing"
"encoding/json"
"technoparkdb/common"
"github.com/HaseProgram/technoparkdb/common"
"time"
"technoparkdb/user"
"technoparkdb/database"
"github.com/HaseProgram/technoparkdb/user"
"github.com/HaseProgram/technoparkdb/database"
"strconv"
"github.com/jackc/pgx"
"strings"
Expand Down Expand Up @@ -105,6 +105,8 @@ func Create(c *routing.Context) (string, int) {
var CheckPostArr []CheckPost
db.Prepare("select_user", "SELECT id, nickname FROM users WHERE nickname=$1")
db.Prepare("get_parent","SELECT thread_id FROM posts WHERE id=$1")

//batch := db.BeginBatch()
for _, post := range POST {
var ta CheckPost

Expand Down Expand Up @@ -153,6 +155,7 @@ func Create(c *routing.Context) (string, int) {
authorId := CheckPostArr[index].AuthorId
parentId := CheckPostArr[index].PostParentId
row := transaction.QueryRow("insert_post", authorId, author, message, parentId, threadId, forumId, forumSlug, createdTime)

err := row.Scan(&tres.Created, &tres.Id)
common.Check(err)

Expand Down
2 changes: 1 addition & 1 deletion service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package service

import (
"github.com/go-ozzo/ozzo-routing"
"technoparkdb/database"
"github.com/HaseProgram/technoparkdb/database"
"encoding/json"
"github.com/jackc/pgx"
)
Expand Down
2 changes: 1 addition & 1 deletion thread/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package thread

import (
"github.com/go-ozzo/ozzo-routing"
"technoparkdb/post"
"github.com/HaseProgram/technoparkdb/post"
)

func Route(router *routing.Router) {
Expand Down
4 changes: 2 additions & 2 deletions thread/thread.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package thread
import (
"github.com/go-ozzo/ozzo-routing"
"encoding/json"
"technoparkdb/common"
"technoparkdb/database"
"github.com/HaseProgram/technoparkdb/common"
"github.com/HaseProgram/technoparkdb/database"
"github.com/jackc/pgx"
"time"
"strconv"
Expand Down
4 changes: 2 additions & 2 deletions user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package user
import (
"encoding/json"
"github.com/go-ozzo/ozzo-routing"
"technoparkdb/common"
"technoparkdb/database"
"github.com/HaseProgram/technoparkdb/common"
"github.com/HaseProgram/technoparkdb/database"
"github.com/jackc/pgx"
)

Expand Down

0 comments on commit 87c0f6a

Please sign in to comment.