pirate

command module
v0.0.0-...-860264b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2015 License: CC0-1.0 Imports: 2 Imported by: 0

README

Pirate

Build Status GoDoc Gitter

Introduction

Pirate which sounds like "private" is the website of private docker-registry.

Key Features:

  • Lightweight UI for private registry's information like images/configuration
  • Readonly mode to be used anonymous
  • (TODO) link to internal/external web sites for more detail information for each image

For quick start, checkout the demo website.

Usage

Please run like below

docker run -d -p 5000:5000 --name registry registry
docker run -d -p 9527:9527 --link registry:registry tobegit3hub/pirate
  • Then monitor your docker daemon in http://127.0.0.1:9527.
  • For boot2docker users, please run boot2docker ip to find out the real IP.
Configuration

So far follow configurations are supported, you can pass via like -e PIRATE_MODE=readonly for docker run command.

  • PIRATE_MODE=readonly|DELETE : default is DELETE, disable DELETE operation for each image, good for anonymous access
  • REGISTRY_URL=<registry url> : default is registry:5000, don't put http in front.

Feature: More docker image information

see detail in issue #18

In order to get more information for docker image, it is planned to store image information inside docker image, Since current registry API just provide simple info.

In Dockerfile, this could be good practice for your Dockerfile. It can be used for other purpose as well

ADD . /app

Then in this app, it will scan the /registry raw data to retrieve this information

root@boot2docker:/mnt/sda1/var/lib/docker/aufs/diff/b3f7db6bab993bf243713b94d657aff4982be95b344c7abfd5941b339de073ec# ls -1 app
Dockerfile
LICENSE
README.md
DOCKER.pkg
data
...
Share data between registry

In order to let pirate get registry data, it needs to be shared (you can use data container as well)

For example you have /mnt/sda1/registry for sharing data (boot2docker env)

# mkdir /mnt/sda1/registry
docker run -d -p 5000:5000 -v /mnt/sda1/registry:/tmp/registry --name registry registry
docker run -d -p 9527:9527 -v /mnt/sda1/registry:/registry --link registry:registry tobegit3hub/pirate

Testing

Tag local testing images

docker tag hello-world localhost:5000/hello-world
docker tag hello-world localhost:5000/hello-world:1.0
docker tag hello-world localhost:5000/larrycai/hello-world

Push images into registry

docker push localhost:5000/hello-world
docker push localhost:5000/hello-world:1.0
docker push localhost:5000/larrycai/hello-world	

Get Involved

Pirate is implemented in Go and JavaScript with tools like Beego, AngularJS, Bootstrap, Bower, JQuery and Docker. You can fork the repository and send pull-request as you want.

  • Setup go path and try echo $GOPATH
  • go get github.com/astaxie/beego
  • go get github.com/tobegit3hub/pirate
  • ./pirate
Debug locally inside docker

git clone the code to the local directly, it is ok for Windows & MacOS as well, for example ~/git/docker/pirate

Then simple use shared folder to debug it

docker run -it -p 9527:9527 --link registry:registry -v $PWD:/go/src/github.com/tobegit3hub/pirate tobegit3hub/pirate bash
root@55640c0fb4f3:/go/src/github.com/tobegit3hub/pirate# go run pirate.go

If you want to have docker image feature

docker run -it -p 9527:9527 --link registry:registry -v /mnt/sda1/registry:/registry -v $PWD:/go/src/github.com/tobegit3hub/pirate tobegit3hub/pirate bash
root@55640c0fb4f3:/go/src/github.com/tobegit3hub/pirate# go run pirate.go

More detail in seagull-design-and-implement and we have excellent documents in docs.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Godeps
_workspace/src/github.com/astaxie/beego
beego is an open-source, high-performance, modularity, full-stack web framework package main import "github.com/astaxie/beego" func main() { beego.Run() } more infomation: http://beego.me
beego is an open-source, high-performance, modularity, full-stack web framework package main import "github.com/astaxie/beego" func main() { beego.Run() } more infomation: http://beego.me
_workspace/src/github.com/astaxie/beego/cache
Usage: import( "github.com/astaxie/beego/cache" ) bm, err := cache.NewCache("memory", `{"interval":60}`) Use it like this: bm.Put("astaxie", 1, 10) bm.Get("astaxie") bm.IsExist("astaxie") bm.Delete("astaxie") more docs http://beego.me/docs/module/cache.md
Usage: import( "github.com/astaxie/beego/cache" ) bm, err := cache.NewCache("memory", `{"interval":60}`) Use it like this: bm.Put("astaxie", 1, 10) bm.Get("astaxie") bm.IsExist("astaxie") bm.Delete("astaxie") more docs http://beego.me/docs/module/cache.md
_workspace/src/github.com/astaxie/beego/cache/memcache
package memcahe for cache provider depend on github.com/bradfitz/gomemcache/memcache go install github.com/bradfitz/gomemcache/memcache Usage: import( _ "github.com/astaxie/beego/cache/memcache" "github.com/astaxie/beego/cache" ) bm, err := cache.NewCache("memcache", `{"conn":"127.0.0.1:11211"}`) more docs http://beego.me/docs/module/cache.md
package memcahe for cache provider depend on github.com/bradfitz/gomemcache/memcache go install github.com/bradfitz/gomemcache/memcache Usage: import( _ "github.com/astaxie/beego/cache/memcache" "github.com/astaxie/beego/cache" ) bm, err := cache.NewCache("memcache", `{"conn":"127.0.0.1:11211"}`) more docs http://beego.me/docs/module/cache.md
_workspace/src/github.com/astaxie/beego/cache/redis
package redis for cache provider depend on github.com/garyburd/redigo/redis go install github.com/garyburd/redigo/redis Usage: import( _ "github.com/astaxie/beego/cache/redis" "github.com/astaxie/beego/cache" ) bm, err := cache.NewCache("redis", `{"conn":"127.0.0.1:11211"}`) more docs http://beego.me/docs/module/cache.md
package redis for cache provider depend on github.com/garyburd/redigo/redis go install github.com/garyburd/redigo/redis Usage: import( _ "github.com/astaxie/beego/cache/redis" "github.com/astaxie/beego/cache" ) bm, err := cache.NewCache("redis", `{"conn":"127.0.0.1:11211"}`) more docs http://beego.me/docs/module/cache.md
_workspace/src/github.com/astaxie/beego/config
Usage: import( "github.com/astaxie/beego/config" ) cnf, err := config.NewConfig("ini", "config.conf") cnf APIS: cnf.Set(key, val string) error cnf.String(key string) string cnf.Strings(key string) []string cnf.Int(key string) (int, error) cnf.Int64(key string) (int64, error) cnf.Bool(key string) (bool, error) cnf.Float(key string) (float64, error) cnf.DefaultString(key string, defaultval string) string cnf.DefaultStrings(key string, defaultval []string) []string cnf.DefaultInt(key string, defaultval int) int cnf.DefaultInt64(key string, defaultval int64) int64 cnf.DefaultBool(key string, defaultval bool) bool cnf.DefaultFloat(key string, defaultval float64) float64 cnf.DIY(key string) (interface{}, error) cnf.GetSection(section string) (map[string]string, error) cnf.SaveConfigFile(filename string) error more docs http://beego.me/docs/module/config.md
Usage: import( "github.com/astaxie/beego/config" ) cnf, err := config.NewConfig("ini", "config.conf") cnf APIS: cnf.Set(key, val string) error cnf.String(key string) string cnf.Strings(key string) []string cnf.Int(key string) (int, error) cnf.Int64(key string) (int64, error) cnf.Bool(key string) (bool, error) cnf.Float(key string) (float64, error) cnf.DefaultString(key string, defaultval string) string cnf.DefaultStrings(key string, defaultval []string) []string cnf.DefaultInt(key string, defaultval int) int cnf.DefaultInt64(key string, defaultval int64) int64 cnf.DefaultBool(key string, defaultval bool) bool cnf.DefaultFloat(key string, defaultval float64) float64 cnf.DIY(key string) (interface{}, error) cnf.GetSection(section string) (map[string]string, error) cnf.SaveConfigFile(filename string) error more docs http://beego.me/docs/module/config.md
_workspace/src/github.com/astaxie/beego/config/xml
package xml for config provider depend on github.com/beego/x2j go install github.com/beego/x2j Usage: import( _ "github.com/astaxie/beego/config/xml" "github.com/astaxie/beego/config" ) cnf, err := config.NewConfig("xml", "config.xml") more docs http://beego.me/docs/module/config.md
package xml for config provider depend on github.com/beego/x2j go install github.com/beego/x2j Usage: import( _ "github.com/astaxie/beego/config/xml" "github.com/astaxie/beego/config" ) cnf, err := config.NewConfig("xml", "config.xml") more docs http://beego.me/docs/module/config.md
_workspace/src/github.com/astaxie/beego/config/yaml
package yaml for config provider depend on github.com/beego/goyaml2 go install github.com/beego/goyaml2 Usage: import( _ "github.com/astaxie/beego/config/yaml" "github.com/astaxie/beego/config" ) cnf, err := config.NewConfig("yaml", "config.yaml") more docs http://beego.me/docs/module/config.md
package yaml for config provider depend on github.com/beego/goyaml2 go install github.com/beego/goyaml2 Usage: import( _ "github.com/astaxie/beego/config/yaml" "github.com/astaxie/beego/config" ) cnf, err := config.NewConfig("yaml", "config.yaml") more docs http://beego.me/docs/module/config.md
_workspace/src/github.com/astaxie/beego/context
Usage: import "github.com/astaxie/beego/context" ctx := context.Context{Request:req,ResponseWriter:rw} more docs http://beego.me/docs/module/context.md
Usage: import "github.com/astaxie/beego/context" ctx := context.Context{Request:req,ResponseWriter:rw} more docs http://beego.me/docs/module/context.md
_workspace/src/github.com/astaxie/beego/example/chat
Beego (http://beego.me/) @description beego is an open-source, high-performance web framework for the Go programming language.
Beego (http://beego.me/) @description beego is an open-source, high-performance web framework for the Go programming language.
_workspace/src/github.com/astaxie/beego/httplib
Usage: import "github.com/astaxie/beego/httplib" b := httplib.Post("http://beego.me/") b.Param("username","astaxie") b.Param("password","123456") b.PostFile("uploadfile1", "httplib.pdf") b.PostFile("uploadfile2", "httplib.txt") str, err := b.String() if err != nil { t.Fatal(err) } fmt.Println(str) more docs http://beego.me/docs/module/httplib.md
Usage: import "github.com/astaxie/beego/httplib" b := httplib.Post("http://beego.me/") b.Param("username","astaxie") b.Param("password","123456") b.PostFile("uploadfile1", "httplib.pdf") b.PostFile("uploadfile2", "httplib.txt") str, err := b.String() if err != nil { t.Fatal(err) } fmt.Println(str) more docs http://beego.me/docs/module/httplib.md
_workspace/src/github.com/astaxie/beego/logs
Usage: import "github.com/astaxie/beego/logs" log := NewLogger(10000) log.SetLogger("console", "") > the first params stand for how many channel Use it like this: log.Trace("trace") log.Info("info") log.Warn("warning") log.Debug("debug") log.Critical("critical") more docs http://beego.me/docs/module/logs.md
Usage: import "github.com/astaxie/beego/logs" log := NewLogger(10000) log.SetLogger("console", "") > the first params stand for how many channel Use it like this: log.Trace("trace") log.Info("info") log.Warn("warning") log.Debug("debug") log.Critical("critical") more docs http://beego.me/docs/module/logs.md
_workspace/src/github.com/astaxie/beego/middleware
Usage: import "github.com/astaxie/beego/middleware" I18N = middleware.NewLocale("conf/i18n.conf", beego.AppConfig.String("language")) more docs: http://beego.me/docs/module/i18n.md
Usage: import "github.com/astaxie/beego/middleware" I18N = middleware.NewLocale("conf/i18n.conf", beego.AppConfig.String("language")) more docs: http://beego.me/docs/module/i18n.md
_workspace/src/github.com/astaxie/beego/migration
migration package for migration The table structure is as follow: CREATE TABLE `migrations` ( `id_migration` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'surrogate key', `name` varchar(255) DEFAULT NULL COMMENT 'migration name, unique', `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'date migrated or rolled back', `statements` longtext COMMENT 'SQL statements for this migration', `rollback_statements` longtext, `status` enum('update','rollback') DEFAULT NULL COMMENT 'update indicates it is a normal migration while rollback means this migration is rolled back', PRIMARY KEY (`id_migration`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
migration package for migration The table structure is as follow: CREATE TABLE `migrations` ( `id_migration` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'surrogate key', `name` varchar(255) DEFAULT NULL COMMENT 'migration name, unique', `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'date migrated or rolled back', `statements` longtext COMMENT 'SQL statements for this migration', `rollback_statements` longtext, `status` enum('update','rollback') DEFAULT NULL COMMENT 'update indicates it is a normal migration while rollback means this migration is rolled back', PRIMARY KEY (`id_migration`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
_workspace/src/github.com/astaxie/beego/orm
Simple Usage package main import ( "fmt" "github.com/astaxie/beego/orm" _ "github.com/go-sql-driver/mysql" // import your used driver ) // Model Struct type User struct { Id int `orm:"auto"` Name string `orm:"size(100)"` } func init() { orm.RegisterDataBase("default", "mysql", "root:root@/my_db?charset=utf8", 30) } func main() { o := orm.NewOrm() user := User{Name: "slene"} // insert id, err := o.Insert(&user) // update user.Name = "astaxie" num, err := o.Update(&user) // read one u := User{Id: user.Id} err = o.Read(&u) // delete num, err = o.Delete(&u) } more docs: http://beego.me/docs/mvc/model/overview.md
Simple Usage package main import ( "fmt" "github.com/astaxie/beego/orm" _ "github.com/go-sql-driver/mysql" // import your used driver ) // Model Struct type User struct { Id int `orm:"auto"` Name string `orm:"size(100)"` } func init() { orm.RegisterDataBase("default", "mysql", "root:root@/my_db?charset=utf8", 30) } func main() { o := orm.NewOrm() user := User{Name: "slene"} // insert id, err := o.Insert(&user) // update user.Name = "astaxie" num, err := o.Update(&user) // read one u := User{Id: user.Id} err = o.Read(&u) // delete num, err = o.Delete(&u) } more docs: http://beego.me/docs/mvc/model/overview.md
_workspace/src/github.com/astaxie/beego/plugins/apiauth
Package apiauth provides handlers to enable apiauth support.
Package apiauth provides handlers to enable apiauth support.
_workspace/src/github.com/astaxie/beego/plugins/auth
Package auth provides handlers to enable basic auth support.
Package auth provides handlers to enable basic auth support.
_workspace/src/github.com/astaxie/beego/plugins/cors
Package cors provides handlers to enable CORS support.
Package cors provides handlers to enable CORS support.
_workspace/src/github.com/astaxie/beego/session
package session provider Usage: import( "github.com/astaxie/beego/session" ) func init() { globalSessions, _ = session.NewManager("memory", `{"cookieName":"gosessionid", "enableSetCookie,omitempty": true, "gclifetime":3600, "maxLifetime": 3600, "secure": false, "sessionIDHashFunc": "sha1", "sessionIDHashKey": "", "cookieLifeTime": 3600, "providerConfig": ""}`) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
package session provider Usage: import( "github.com/astaxie/beego/session" ) func init() { globalSessions, _ = session.NewManager("memory", `{"cookieName":"gosessionid", "enableSetCookie,omitempty": true, "gclifetime":3600, "maxLifetime": 3600, "secure": false, "sessionIDHashFunc": "sha1", "sessionIDHashKey": "", "cookieLifeTime": 3600, "providerConfig": ""}`) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
_workspace/src/github.com/astaxie/beego/session/couchbase
package couchbase for session provider depend on github.com/couchbaselabs/go-couchbasee go install github.com/couchbaselabs/go-couchbase Usage: import( _ "github.com/astaxie/beego/session/couchbase" "github.com/astaxie/beego/session" ) func init() { globalSessions, _ = session.NewManager("couchbase", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"http://host:port/, Pool, Bucket"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
package couchbase for session provider depend on github.com/couchbaselabs/go-couchbasee go install github.com/couchbaselabs/go-couchbase Usage: import( _ "github.com/astaxie/beego/session/couchbase" "github.com/astaxie/beego/session" ) func init() { globalSessions, _ = session.NewManager("couchbase", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"http://host:port/, Pool, Bucket"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
_workspace/src/github.com/astaxie/beego/session/memcache
package memcache for session provider depend on github.com/bradfitz/gomemcache/memcache go install github.com/bradfitz/gomemcache/memcache Usage: import( _ "github.com/astaxie/beego/session/memcache" "github.com/astaxie/beego/session" ) func init() { globalSessions, _ = session.NewManager("memcache", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:11211"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
package memcache for session provider depend on github.com/bradfitz/gomemcache/memcache go install github.com/bradfitz/gomemcache/memcache Usage: import( _ "github.com/astaxie/beego/session/memcache" "github.com/astaxie/beego/session" ) func init() { globalSessions, _ = session.NewManager("memcache", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:11211"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
_workspace/src/github.com/astaxie/beego/session/mysql
package mysql for session provider depends on github.com/go-sql-driver/mysql: go install github.com/go-sql-driver/mysql mysql session support need create table as sql: CREATE TABLE `session` ( `session_key` char(64) NOT NULL, session_data` blob, `session_expiry` int(11) unsigned NOT NULL, PRIMARY KEY (`session_key`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; Usage: import( _ "github.com/astaxie/beego/session/mysql" "github.com/astaxie/beego/session" ) func init() { globalSessions, _ = session.NewManager("mysql", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"[username[:password]@][protocol[(address)]]/dbname[?param1=value1&...&paramN=valueN]"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
package mysql for session provider depends on github.com/go-sql-driver/mysql: go install github.com/go-sql-driver/mysql mysql session support need create table as sql: CREATE TABLE `session` ( `session_key` char(64) NOT NULL, session_data` blob, `session_expiry` int(11) unsigned NOT NULL, PRIMARY KEY (`session_key`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; Usage: import( _ "github.com/astaxie/beego/session/mysql" "github.com/astaxie/beego/session" ) func init() { globalSessions, _ = session.NewManager("mysql", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"[username[:password]@][protocol[(address)]]/dbname[?param1=value1&...&paramN=valueN]"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
_workspace/src/github.com/astaxie/beego/session/postgres
SessionOn = true SessionProvider = postgresql SessionSavePath = "user=a password=b dbname=c sslmode=disable" SessionName = session Usage: import( _ "github.com/astaxie/beego/session/postgresql" "github.com/astaxie/beego/session" ) func init() { globalSessions, _ = session.NewManager("postgresql", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"user=pqgotest dbname=pqgotest sslmode=verify-full"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
SessionOn = true SessionProvider = postgresql SessionSavePath = "user=a password=b dbname=c sslmode=disable" SessionName = session Usage: import( _ "github.com/astaxie/beego/session/postgresql" "github.com/astaxie/beego/session" ) func init() { globalSessions, _ = session.NewManager("postgresql", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"user=pqgotest dbname=pqgotest sslmode=verify-full"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
_workspace/src/github.com/astaxie/beego/session/redis
package redis for session provider depend on github.com/garyburd/redigo/redis go install github.com/garyburd/redigo/redis Usage: import( _ "github.com/astaxie/beego/session/redis" "github.com/astaxie/beego/session" ) func init() { globalSessions, _ = session.NewManager("redis", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:7070"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
package redis for session provider depend on github.com/garyburd/redigo/redis go install github.com/garyburd/redigo/redis Usage: import( _ "github.com/astaxie/beego/session/redis" "github.com/astaxie/beego/session" ) func init() { globalSessions, _ = session.NewManager("redis", “{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:7070"}“) go globalSessions.GC() } more docs: http://beego.me/docs/module/session.md
swagger struct definition
_workspace/src/github.com/astaxie/beego/toolbox
toolbox healthcheck type DatabaseCheck struct { } func (dc *DatabaseCheck) Check() error { if dc.isConnected() { return nil } else { return errors.New("can't connect database") } } AddHealthCheck("database",&DatabaseCheck{}) more docs: http://beego.me/docs/module/toolbox.md
toolbox healthcheck type DatabaseCheck struct { } func (dc *DatabaseCheck) Check() error { if dc.isConnected() { return nil } else { return errors.New("can't connect database") } } AddHealthCheck("database",&DatabaseCheck{}) more docs: http://beego.me/docs/module/toolbox.md
_workspace/src/github.com/astaxie/beego/utils/captcha
an example for use captcha “` package controllers import ( "github.com/astaxie/beego" "github.com/astaxie/beego/cache" "github.com/astaxie/beego/utils/captcha" ) var cpt *captcha.Captcha func init() { // use beego cache system store the captcha data store := cache.NewMemoryCache() cpt = captcha.NewWithFilter("/captcha/", store) } type MainController struct { beego.Controller } func (this *MainController) Get() { this.TplNames = "index.tpl" } func (this *MainController) Post() { this.TplNames = "index.tpl" this.Data["Success"] = cpt.VerifyReq(this.Ctx.Request) } “` template usage “` {{.Success}} <form action="/" method="post"> {{create_captcha}} <input name="captcha" type="text"> </form> “`
an example for use captcha “` package controllers import ( "github.com/astaxie/beego" "github.com/astaxie/beego/cache" "github.com/astaxie/beego/utils/captcha" ) var cpt *captcha.Captcha func init() { // use beego cache system store the captcha data store := cache.NewMemoryCache() cpt = captcha.NewWithFilter("/captcha/", store) } type MainController struct { beego.Controller } func (this *MainController) Get() { this.TplNames = "index.tpl" } func (this *MainController) Post() { this.TplNames = "index.tpl" this.Data["Success"] = cpt.VerifyReq(this.Ctx.Request) } “` template usage “` {{.Success}} <form action="/" method="post"> {{create_captcha}} <input name="captcha" type="text"> </form> “`
_workspace/src/github.com/astaxie/beego/validation
package for validations import ( "github.com/astaxie/beego/validation" "log" ) type User struct { Name string Age int } func main() { u := User{"man", 40} valid := validation.Validation{} valid.Required(u.Name, "name") valid.MaxSize(u.Name, 15, "nameMax") valid.Range(u.Age, 0, 140, "age") if valid.HasErrors() { // validation does not pass // print invalid message for _, err := range valid.Errors { log.Println(err.Key, err.Message) } } // or use like this if v := valid.Max(u.Age, 140); !v.Ok { log.Println(v.Error.Key, v.Error.Message) } } more info: http://beego.me/docs/mvc/controller/validation.md
package for validations import ( "github.com/astaxie/beego/validation" "log" ) type User struct { Name string Age int } func main() { u := User{"man", 40} valid := validation.Validation{} valid.Required(u.Name, "name") valid.MaxSize(u.Name, 15, "nameMax") valid.Range(u.Age, 0, 140, "age") if valid.HasErrors() { // validation does not pass // print invalid message for _, err := range valid.Errors { log.Println(err.Key, err.Message) } } // or use like this if v := valid.Max(u.Age, 140); !v.Ok { log.Println(v.Error.Key, v.Error.Message) } } more info: http://beego.me/docs/mvc/controller/validation.md

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL