Skip to content
This repository was archived by the owner on Apr 19, 2023. It is now read-only.

Commit baf900a

Browse files
committed
update go-on-rails to 0.3.0
1 parent 16e08c4 commit baf900a

File tree

13 files changed

+335
-193
lines changed

13 files changed

+335
-193
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ gem 'jbuilder', '~> 2.5'
3333

3434
# Use Capistrano for deployment
3535
# gem 'capistrano-rails', group: :development
36-
gem 'go-on-rails', '~> 0.1.11'
36+
gem 'go-on-rails', '~> 0.3.0'
3737
gem 'devise'
3838
gem 'rails_admin', '~> 1.2'
3939
gem 'cancancan', '~> 2.0'

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ GEM
7979
railties (>= 3.2, < 5.2)
8080
globalid (0.4.0)
8181
activesupport (>= 4.2.0)
82-
go-on-rails (0.1.11)
82+
go-on-rails (0.3.0)
8383
haml (5.0.2)
8484
temple (>= 0.8.0)
8585
tilt
@@ -247,7 +247,7 @@ DEPENDENCIES
247247
capybara (~> 2.13)
248248
coffee-rails (~> 4.2)
249249
devise
250-
go-on-rails (~> 0.1.11)
250+
go-on-rails (~> 0.3.0)
251251
jbuilder (~> 2.5)
252252
listen (>= 3.0.5, < 3.2)
253253
mysql2 (>= 0.3.18, < 0.5)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ end
5656
Now let's create a `Post` model:
5757

5858
```bash
59-
rails g model Post title context:text user_id:integer
59+
rails g model Post title content:text user_id:integer
6060
```
6161

6262
then we edit them as `user` has many `posts` association.

docker-compose.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
version: '3'
2+
3+
services:
4+
# generated according to the config/database.yml
5+
database:
6+
image: mysql
7+
ports:
8+
- '3306:3306'
9+
10+
# rails app part. You need to modify this part by your project
11+
# and create a Dockerfile for it before you run any docker-compose command
12+
rails_app:
13+
build: .
14+
command: bundle exec rails s -p 3000 -b '0.0.0.0'
15+
ports:
16+
- "3000:3000"
17+
depends_on:
18+
- database
19+
20+
# golang app part. It depends on the rails_app to initialize the database
21+
go_app:
22+
build: ./go_app
23+
command: ./myapp -port 4000
24+
environment:
25+
# Gin webserver run mode. Or "debug" for debugging
26+
- GIN_MODE=release
27+
ports:
28+
- "4000:4000"
29+
depends_on:
30+
- database
31+
- rails_app

go_app/Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Multi-stage builds require Docker 17.05 or higher on the daemon and client.
2+
# see: https://docs.docker.com/engine/userguide/eng-image/multistage-build/
3+
4+
# build the go app binary
5+
FROM golang:1.9.2 as builder
6+
WORKDIR /root/
7+
COPY . /root/
8+
RUN perl -pi -e "s/tcp\(.*?:/tcp\(database:/; s/host=\S+? /host=database /" models/db.go
9+
RUN make deps
10+
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o myapp .
11+
12+
# use the binary app to build the target image
13+
FROM alpine:latest
14+
WORKDIR /root/
15+
ADD views /root/views
16+
ADD public /root/public
17+
COPY --from=builder /root/myapp .
18+
CMD ["./myapp"]

go_app/Makefile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
GO := go
2+
MYAPP := myapp
3+
IMAGE := $(MYAPP)
4+
TAG := latest
5+
6+
$(MYAPP):
7+
$(GO) build -o $(MYAPP)
8+
9+
clean:
10+
-rm $(MYAPP)
11+
12+
build: $(MYAPP)
13+
@:
14+
15+
deps:
16+
$(GO) get -u github.com/jmoiron/sqlx \
17+
github.com/gin-gonic/gin \
18+
github.com/goonr/go-sqlite3 \
19+
github.com/go-sql-driver/mysql \
20+
github.com/lib/pq \
21+
github.com/asaskevich/govalidator
22+
23+
test:
24+
$(GO) test -v ./models
25+
26+
run: $(MYAPP)
27+
./$(MYAPP)
28+
29+
image: clean
30+
docker build -t $(USER)/$(IMAGE):$(TAG) .
31+
32+
.PHONY: build clean deps test run image
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package controllers
2+
3+
import (
4+
"net/http"
5+
6+
"github.com/gin-gonic/gin"
7+
// you can import models
8+
//m "../models"
9+
)
10+
11+
func HomeHandler(c *gin.Context) {
12+
// you can use model functions to do CRUD
13+
//
14+
// user, _ := m.FindUser(1)
15+
// u, err := json.Marshal(user)
16+
// if err != nil {
17+
// log.Printf("JSON encoding error: %v\n", err)
18+
// u = []byte("Get data error!")
19+
// }
20+
21+
type Envs struct {
22+
GoOnRailsVer string
23+
GolangVer string
24+
}
25+
26+
gorVer := "0.3.0"
27+
golangVer := "go version go1.9.2 darwin/amd64"
28+
29+
envs := Envs{GoOnRailsVer: gorVer, GolangVer: golangVer}
30+
c.HTML(http.StatusOK, "index.tmpl", envs)
31+
}

go_app/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
)
1010

1111
func main() {
12-
// The app will run on port 3000 by default, you can custom it with the flag -port
13-
servePort := flag.String("port", "3000", "Http Server Port")
12+
// The app will run on port 4000 by default, you can custom it with the flag -port
13+
servePort := flag.String("port", "4000", "Http Server Port")
1414
flag.Parse()
1515

1616
// Here we are instantiating the router

0 commit comments

Comments
 (0)