Skip to content

Commit

Permalink
Updated examples
Browse files Browse the repository at this point in the history
Updated booking app to go.mod
Updated chat, facebook, others app to add in go file in the root
Updated travis to run tests in windows
Updated travis to exclude testing fasthttp on windows
  • Loading branch information
[email protected] committed May 30, 2020
1 parent 5b25a51 commit dc75997
Show file tree
Hide file tree
Showing 18 changed files with 300 additions and 600 deletions.
61 changes: 40 additions & 21 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
language: go

go:
- "1.9"
- "1.10"
- "1.11"
- "1.12"
- "1.13"
- "1.14"
- "tip"

os:
Expand All @@ -23,47 +23,66 @@ services:
- memcache
- redis-server

env:
# Setting environments variables
- GO111MODULEsss=auto

before_install:
# TRAVIS_OS_NAME - linux and osx
- echo $TRAVIS_OS_NAME
- |
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
brew update && brew install memcached redis && brew services start redis && brew services start memcached
fi
- redis-server --daemonize yes
- redis-cli info
#- |
# if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
# brew update && brew install memcached redis && brew services start redis && brew services start memcached
# fi
#- redis-server --daemonize yes
#- redis-cli info

install:
# Setting environments variables
- export PATH=$PATH:$HOME/gopath/bin
- export REVEL_BRANCH="develop"
- 'if [[ "$TRAVIS_BRANCH" == "master" ]]; then export REVEL_BRANCH="master"; fi'
- 'echo "Travis branch: $TRAVIS_BRANCH, Revel dependency branch: $REVEL_BRANCH"'
- git clone -b $REVEL_BRANCH git://github.com/revel/modules ../modules/
# - go mod edit -replace "github.com/revel/revel=github.com/revel/revel@$REVEL_BRANCH" examples/booking/go.mod
# Build the revel CLI based on branch
- export GO111MODULE=on
- git clone -b $REVEL_BRANCH git://github.com/revel/cmd
- cd cmd; go build -o $GOPATH/bin/revel github.com/revel/cmd/revel; ls -lah $GOPATH/bin; cd ..; rm -rf cmd
# Update the go.mod files in the example folder with the correct branch
- |
for file in booking ; do echo "$file is a directory";
cat $file/go.mod
echo "replace github.com/revel/modules => github.com/revel/modules $REVEL_BRANCH" >> $file/go.mod
echo "replace github.com/revel/revel => github.com/revel/revel $REVEL_BRANCH" >> $file/go.mod
done
# Checkout the other projects to test backwards compatibility
- export GO111MODULE=auto
- git clone -b $REVEL_BRANCH git://github.com/revel/revel ../revel/
- git clone -b $REVEL_BRANCH git://github.com/revel/cmd ../cmd/
- git clone -b $REVEL_BRANCH git://github.com/revel/modules ../modules/
- git clone -b $REVEL_BRANCH git://github.com/revel/config ../config/
- git clone -b $REVEL_BRANCH git://github.com/revel/cron ../cron/
- go get -t -v github.com/revel/revel/...
- go get -t -v github.com/revel/cmd/revel


script:
# Commented out persona test sample, since persona.org gonna be shutdown.
# Also http://personatestuser.org becomes non-responsive most of the time.
# https://wiki.mozilla.org/Identity/Persona_Shutdown_Guidelines_for_Reliers
# - revel test github.com/revel/examples/persona
# Build & run the sample apps
- revel test -v -a github.com/revel/examples/booking
- revel test -v -a github.com/revel/examples/booking -m dev-fast
- revel test -v -a github.com/revel/examples/booking2
- go test -v github.com/revel/examples/booking/app/... -args -revel.importPath=github.com/revel/examples/booking
- revel test -v -a github.com/revel/examples/chat
- revel test -v -a github.com/revel/examples/facebook-oauth2
- revel test -v -a github.com/revel/examples/twitter-oauth
- revel test -v -a github.com/revel/examples/validation
- revel test -v -a github.com/revel/examples/upload

# Should not need gopath to run
- mkdir GOPATHBACKUP
- export GOPATH=$PWD/GOPATHBACKUP
# Build & run the sample apps
- revel test -v -a booking
# fast http not supported on windows
- if [[ "$TRAVIS_OS_NAME" != "windows" ]]; then revel test -v -a booking -m dev-fast; fi
# This test cannot be done at this time on go.mod projects
#- cd booking; go test -v github.com/revel/examples/booking/app/... -args -revel.importPath=github.com/revel/examples/booking; cd ..

matrix:
allow_failures:
- os: windows
- go: tip
91 changes: 90 additions & 1 deletion booking/app/controllers/hotels.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
//go:generate swagger generate spec -o swagger.json

// Package classification Swagger Hotel Example.
// Swagger Hotel Example
//
//
//
// Schemes: https
// Host: hotel.example.revelframework.com
// BasePath: /
// Version: 1.0.0
// License: MIT http://opensource.org/licenses/MIT
// Contact: Name<[email protected]> https://www.somewhere.com
//
// Consumes:
// - application/json
// - application/x-www-form-urlencoded
//
// Produces:
// - text/html
//
//
//
//
// swagger:meta

package controllers

import (
Expand All @@ -11,7 +37,7 @@ import (
"github.com/revel/examples/booking/app/models"
"github.com/revel/examples/booking/app/routes"

"gopkg.in/Masterminds/squirrel.v1"
"github.com/Masterminds/squirrel"
)

type Hotels struct {
Expand Down Expand Up @@ -40,6 +66,69 @@ func (c Hotels) Index() revel.Result {
return c.Render(bookings)
}

// swagger:route GET /hotels/ListJson enter demo
//
// Enter Demo
//
//
// Consumes:
// - application/x-www-form-urlencoded
//
// Produces:
// - text/html
//
// Schemes: https
//
//
// Responses:
// 200: Success
// 401: Invalid User

// swagger:operation GET /demo demo
//
// Enter Demo
//
//
// ---
// produces:
// - text/html
// parameters:
// - name: user
// in: formData
// description: user
// required: true
// type: string
// - name: demo
// in: formData
// description: demo
// required: true
// type: string
// responses:
// '200':
// description: Success
// '401':
// description: Invalid User
func (c Hotels) ListJson(search string, size, page uint64) revel.Result {
if page == 0 {
page = 1
}
nextPage := page + 1
search = strings.TrimSpace(search)

var hotels []*models.Hotel
builder := c.Db.SqlStatementBuilder.Select("*").From("Hotel").Offset((page - 1) * size).Limit(size)
if search != "" {
search = "%" + strings.ToLower(search) + "%"
builder = builder.Where(squirrel.Or{
squirrel.Expr("lower(Name) like ?", search),
squirrel.Expr("lower(City) like ?", search)})
}
if _, err := c.Txn.Select(&hotels, builder); err != nil {
c.Log.Fatal("Unexpected error loading hotels", "error", err)
}

return c.RenderJSON(map[string]interface{}{"hotels":hotels, "search":search, "size":size, "page":page, "nextPage":nextPage})
}
func (c Hotels) List(search string, size, page uint64) revel.Result {
if page == 0 {
page = 1
Expand Down
9 changes: 8 additions & 1 deletion booking/app/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (
"github.com/revel/revel"
"github.com/valyala/fasthttp"
"golang.org/x/crypto/bcrypt"
"gopkg.in/gorp.v2"
"github.com/go-gorp/gorp"
"net/http"
"time"
"os"
"github.com/revel/revel/logger"
)

func init() {
Expand All @@ -28,6 +30,11 @@ func init() {
revel.CompressFilter, // Compress the result.
revel.ActionInvoker, // Invoke the action.
}
logger.LogFunctionMap["stdoutjson"]=
func(c *logger.CompositeMultiHandler, options *logger.LogOptions) {
// Set the json formatter to os.Stdout, replace any existing handlers for the level specified
c.SetJson(os.Stdout, options)
}
revel.AddInitEventHandler(func(event revel.Event, i interface{}) revel.EventResponse {
switch event {
case revel.ENGINE_BEFORE_INITIALIZED:
Expand Down
2 changes: 1 addition & 1 deletion booking/app/models/booking.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/revel/revel"
"regexp"
"time"
"gopkg.in/gorp.v2"
"github.com/go-gorp/gorp"
)

type Booking struct {
Expand Down
17 changes: 10 additions & 7 deletions booking/conf/app.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
app.name=Booking example
app.secret=secret

# Server
http.addr=
# Server, listen on all interfaces by using 0.0.0.0
http.addr=0.0.0.0
http.port=9000
http.ssl=false
http.sslcert=
Expand All @@ -17,9 +17,9 @@ db.connection = file::memory:?mode=memory&cache=shared

build.tags=gorp

module.jobs=github.com/revel/modules/jobs
module.static=github.com/revel/modules/static
module.gorp=github.com/revel/modules/orm/gorp
module.0.static=github.com/revel/modules/static
module.1.jobs=github.com/revel/modules/jobs
module.2.gorp=github.com/revel/modules/orm/gorp

[dev]
# Logging
Expand All @@ -28,7 +28,7 @@ log.all.output = stderr
mode.dev=true
watch=true
watch.mode=eager
module.testrunner=github.com/revel/modules/testrunner
module.3.testrunner=github.com/revel/modules/testrunner

[dev-app]
# Logging
Expand All @@ -41,9 +41,12 @@ watch=true
watch.mode=eager
module.testrunner=github.com/revel/modules/testrunner



[dev-fast]
# This mode uses the fasthttp module to serve out web pages, and a custom logger
# Logging
log.all.output = stderr
log.all.output = stdoutjson

mode.dev=true
watch=true
Expand Down
19 changes: 19 additions & 0 deletions booking/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module github.com/revel/examples/booking

go 1.12

require (
github.com/Masterminds/squirrel v1.3.0
github.com/go-gorp/gorp v2.2.0+incompatible
github.com/lib/pq v1.5.0 // indirect
github.com/mattn/go-sqlite3 v2.0.3+incompatible
github.com/pkg/errors v0.9.1 // indirect
github.com/poy/onpar v1.0.0 // indirect
github.com/revel/cmd v0.21.1
github.com/revel/modules v0.21.0
github.com/revel/revel v0.21.0
github.com/valyala/fasthttp v1.12.0
golang.org/x/crypto v0.0.0-20200429183012-4b2356b1ed79
gopkg.in/gorp.v2 v2.2.0 // indirect
)

Loading

0 comments on commit dc75997

Please sign in to comment.