Pages

Showing posts with label revel. Show all posts
Showing posts with label revel. Show all posts

Monday, September 10, 2018

Fedora 28 : The Revel framework with golang.

The development team has a very effective text:
A high productivity, full-stack web framework for the Go language.
They used this words:
Revel provides routing, parameter parsing, validation, session/flash, templating, caching, job running, a testing framework, and even internationalization. I tested it yesterday and today I will show you how effective it is.
This framework is very easy to install and use it with Fedora 28.
I could say this is like django framework with the temptation style.
Let's start with a simple example into a folder created by me and named gocode:
[mythcat@desk ~]$ mkdir ~/gocode
[mythcat@desk ~]$ export GOPATH=~/gocode
[mythcat@desk ~]$ echo export GOPATH=$GOPATH >> ~/.bash_profile
[mythcat@desk ~]$ cd gocode/
[mythcat@desk gocode]$ go get github.com/revel/revel
[mythcat@desk gocode]$ ls
pkg  src
[mythcat@desk gocode]$ go get github.com/revel/cmd/revel
[mythcat@desk gocode]$ ls
bin  pkg  src
[mythcat@desk gocode]$ export PATH="$PATH:$GOPATH/bin"
[mythcat@desk gocode]$ revel helpDEBUG 19:24:09  revel  server.go:27: arguments by adding nil
~
~ revel! http://revel.github.io
~
usage: revel command [arguments]

The commands are:

    new         create a skeleton Revel application
    run         run a Revel application
    build       build a Revel application (e.g. for deployment)
    package     package a Revel application (e.g. for deployment)
    clean       clean a Revel application's temp files
    test        run all tests from the command-line
    version     displays the Revel Framework and Go version

Use "revel help [command]" for more information.
[mythcat@desk gocode]$ ls
bin  pkg  src
[mythcat@desk gocode]$ revel new myapp
DEBUG 19:38:50  revel  server.go:27: RegisterServerEngine: Registered engine 
~
~ revel! http://revel.github.io
~
Your application is ready:
   /home/mythcat/gocode/src/myapp

You can run it with:
   revel run myapp
[mythcat@desk gocode]$ revel run myapp
DEBUG 19:39:15  revel  server.go:27: RegisterServerEngine: Registered engine 
~
~ revel! http://revel.github.io
~
Trying to build with myapp (0x0,0x0)
DEBUG 19:39:15  revel module.go:152: Sorted keys  section=module keys=module.static 
...
Let's see the source code - in this case the default files: app.go and Index.html .
[mythcat@desk gocode]$ cd src/myapp/app/
[mythcat@desk app]$ ls
controllers  init.go  routes  tmp  views
[mythcat@desk app]$ cd controllers/
[mythcat@desk controllers]$ ls
app.go
[mythcat@desk controllers]$ cat app.go 
package controllers

import (
    "github.com/revel/revel"
)

type App struct {
    *revel.Controller
}

func (c App) Index() revel.Result {
    return c.Render()
}

[mythcat@desk App]$ cat Index.html 
The cat command will show the source code of Index.html file.
Let's add a golang variable named greeting to app.go and Index.html files:
[mythcat@desk controllers]$ cat app.go 
package controllers

import (
    "github.com/revel/revel"
)

type App struct {
    *revel.Controller
}

func (c App) Index() revel.Result {
    greeting := "Fedora and revel framework !"
    return c.Render(greeting)
} 
This variable greeting will will be add into file Index.html with tag p after It works!
This is result of two screenshots from start install and after I change with the variable greeting.