GithubHelp home page GithubHelp logo

as's Introduction

as

基于 martini 的轻巧框架

使用

如何开启一个监听80端口的服务:

package main

import (
	"github.com/ascoders/as"
)

func main() {
	as.Run()
}

配置

可以通过as.Conf.*配置任意参数,请注意将它放在as.Run()之前。同时你也可以单独写在一个配置文件中,查看配置列表

func main() {
	as.Conf.Debug = true
	as.Conf.Host = "59.67.115.1"
	as.Conf.Port = 8080
	
	as.Run()
}

控制器

控制器内嵌了as.Controller,这样变包含了所有as.Controller拥有的方法,并自动实现了Restful方法,查看控制器设计

同时定义New方法,由于as是一个restful框架,一个url、一个控制器、一个模型同时对应一个资源,所以将对应模型对象通过NewModel方法注册到其中,供路由使用。

package app

import (
	"github.com/ascoders/as"
	"product/models/app"
	
)

type Controller struct {
	as.Controller
}

func New() *Controller {
	controllerInstance := &Controller{}
	controllerInstance.NewModel(app.ModelInstance)
	return controllerInstance
}

模型

模型同样内嵌as.Model,查看模型设计

type Model struct {
	as.Model
}

路由

as框架使用了注释路由,如下写法可以注册一个/appsurl下的路由,响应get方法的请求,并返回ok,响应号为200.

// @router /apps [get]
func (this *Controller) Gets() (int, []byte) {
	return this.Success("ok")
}

as's People

Contributors

ascoders avatar

Watchers

 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.