Code Monkey home page Code Monkey logo

beauty's Introduction

GoDoc

A simple framwork written in golang.

You can build a simple restful project or a web application with it. If you dosen't want to use mysql db, you can implement your own Auth decorates and session.You can use your own DAO or whatever you like.

quick start:

  • run cmd

    mkdir demo && cd demo
    go get gopkg.in/alecthomas/kingpin.v2
    go get github.com/yang-f/beauty
    
  • add $GOPATH/bin to your $PATH

  • run cmd beauty

    usage: beauty [<flags>] <command> [<args> ...]
    
    A command-line tools of beauty.
    
    Flags:
      --help  Show context-sensitive help (also try --help-long and --help-man).
    
    Commands:
      help [<command>...]
        Show help.
    
      demo
        Demo of web server.
    
      generate <name>
        Generate a new app.
    
  • test beauty

    beauty demo
    
  • then

    2017/05/04 16:21:05 start server on port :8080
  • visit 127.0.0.1:8080

    {"description":"this is json"}
  • visit 127.0.0.1:8080/demo1

    {"description":"this is json"}

How to use:

  • Generate new app

    beauty generate yourAppName
    
  • dir list

    GOPATH/src/yourAppName
    ├── controllers
    │   ├── adminController.go
    │   └── controller_test.go
    ├── decorates
    |   └── http.go
    ├── main.go
    ├── models
    ├── tpl
    └── utils
    
  • about Route

    • demo
        r := router.New()
    
        r.GET("/", controllers.Config().ContentJSON())
    
        r.GET("/demo1", controllers.Config().ContentJSON().Verify())
  • token generate

    tokenString, err := token.Generate(fmt.Sprintf("%v|%v", user_id, user_pass))
  • demo

    package main
    
    import (
        "net/http"
        "log"
        "github.com/yang-f/beauty/consts/contenttype"
        "github.com/yang-f/beauty/router"
        "github.com/yang-f/beauty/settings"
        "github.com/yang-f/beauty/controllers"
        "github.com/yang-f/beauty/decorates"
    
    )
    
    func main() {
    
        log.Printf("start server on port %s", settings.Listen)
    
        settings.Listen = ":8080"
    
        settings.Domain = "yourdomain.com"
    
        settings.DefaultOrigin = "http://defaultorigin.com"
    
        settings.HmacSampleSecret = "whatever"
    
        r := router.New()
    
        r.GET("/", controllers.Config().ContentJSON())
    
        r.GET("/demo1", controllers.Config().ContentJSON().Verify())
    
        log.Fatal(http.ListenAndServe(settings.Listen, r))
    }

Support:

  • token
settings.HmacSampleSecret = "whatever"

token, err := token.Generate(origin)

origin, err := token.Valid(token)
  • cors

    • static file server
    router.PathPrefix("/static/").Handler(http.StripPrefix("/static/", decorates.CorsHeader2(http.FileServer(http.Dir("/your/static/path")))))
    • api etc:
      • default is cors
  • error handler

    func XxxxController() decorates.Handler{
        return func (w http.ResponseWriter, r *http.Request) *models.APPError {
            xxx,err := someOperation()
            if err != nil{
                return &models.APPError {err, Message, Code, Status}
            }
            ...
            return nil
        }
    }
  • utils

    • Response
    • Rand
    • MD5
    • Post
  • test

    • go test -v -bench=".*"
    • go test -v -short $(go list ./... | grep -v /vendor/)
    • ...

Contributing:

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -m 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

TODO:

  • Cmd tools
  • Improve document
  • Role review
  • Error handler

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.