go web framework
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 29 commits ahead of peidachang:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
db
example/firstweb
lib
websock
.gitignore
README.md
auth.go
build.bat
const.go
context.go
crypto.go
gos.go
layout.go
page.go
pprof.go
render.go
router.go
upload.go
webapi.go

README.md

Gos web framework

gos project

|- [app]
	└── app.conf
	├── app.go
	├── [api]
	├── [page]
	├── [upload]
	├── [websock]
|- [webroot]
	├── [assets]
	├── [template]

Installation

Make sure you have the a working Go environment. See the install instructions.

And install gos:

go get github.com/jiorry/gos

The dependence pkg will be installed:

github.com/jiorry/gos/lib/util
github.com/jiorry/gos/lib/log
github.com/jiorry/gos/lib/crypto
github.com/jiorry/gos/lib/conf
github.com/jiorry/gos/lib/redis
github.com/jiorry/gos/lib/cache
github.com/jiorry/gos/lib/i18n
github.com/jiorry/gos/lib/ssdb
github.com/jiorry/gos/db 

##quick start app.go

package main

import (
	"./api"
	"./page"
	"./upload"
	"github.com/jiorry/gos"
	_ "github.com/mattn/go-sqlite3"
)

func main() {
	gos.Init()
	gos.Route("/", (*page.IndexPage)(nil))

	// open api router
	// api url: /api/web
	// conf http: webSocketPrifix
	gos.WebApiRoute("web", (*api.ApiPublicApi)(nil))

	// file upload router
	// upload url: /upload/file
	// conf http: uploadPathPrifix
	gos.FileUploadRoute("file", (*upload.UserFileUpload)(nil))

	// websocket router
	// upload url: /sock/conn
	// conf http: webSocketPrifix
	// gos.WebSocketRoute("conn", (*websock.UserWebSock)(nil))

	gos.Start()
}

index.go

package page

import (
	"github.com/jiorry/gos"
)

type IndexPage struct {
	gos.Page
}

type indexdata struct {
	PageData string
}

func (this *IndexPage) Init() {
	this.Page.Title = "My First Go Web"
	this.AddCss("site.css")
	this.AddJs("jquery.js")
	this.Layout.AddTop(theme, "_header", &renddata{"header"})
	this.Layout.AddBottom(theme, "_footer", &renddata{"footer"})
	this.Data = &indexdata{Name: "my first page"}

	// this.Ctx.Rediect("/")
}
type renddata struct {
	Name string
}

func (this *IndexPage) Action() {
	if this.Ctx.Request.Method=="POST" {
		// do something
	}else{
		// do something
	}
}

_header.htm

<header id="header">
{{.Name}}
</header>

public_api.go

package api

import (
	"fmt"
	"github.com/jiorry/gos"
	"github.com/jiorry/libs/util"
)

type ApiPublicApi struct {
	gos.WebApi
}

func (a *ApiPublicApi) SayHello(args util.MapData) (string, error) {
	msg := args.GetString("message")
	return fmt.Printf("hello: %s", msg), nil
}

api url: /api/web