Giter Site home page Giter Site logo

beer's Introduction

Beer

Beer是一个使用golang开发的轻量级web框架,目的是希望使用这个框架就像夏天坐在路边喝着啤酒吃着烧烤一样的爽。由于参考了一部分的gin代码,所有很多方法与gin的类似。目前还处于维护阶段不能用于生产环境

Examples

package main

import (
	"github.com/houzhongjian/beer"
	"log"
)

func main() {
    //加载配置文件.
	beer.Loadini("./public/conf/app.ini")
	r := beer.New()

	r.Static("/img/", "./public/image")
	r.Static("/conf/", "./public/conf/")
	r.GET("/", Default)
	r.GET("/detail/:id", Detail)
	r.POST("/login", Login)

	if err := r.Run(":8088"); err != nil {
		panic(err)
	}
}

func Default(c *beer.Context) {
	log.Println(c.IP)
	c.Layout = "blog/layout.html"
	c.Data["name"] = "张三"
	c.Data["age"] = 20
	c.Data["title"] = "goBeer"
	c.Html("blog/index.html")
}

func Login(c *beer.Context) {
    session,err := beer.Session().Start(c)
	if err != nil {
		log.Printf("err:%+v\n",err)
		return
	}
	session.Set("name","张三")

	c.Data["code"] = 1000
	c.Data["msg"] = "登录成功"
	c.Json()
}

func Detail(c *beer.Context) {
	log.Println(c.Param("id"))
	log.Println(c.UserAgent)

	c.Layout = "blog/layout.html"
	c.Data["name"] = "zhangsan"
	c.Data["age"] = 20
	c.Data["title"] = "博客标题"
	c.Html("blog/detail.html")
}

beer's People

Contributors

houzhongjian avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.