Skip to content

Instantly share code, notes, and snippets.

View gavinzhou's full-sized avatar
🏠
Working from home

Gavin Zhou gavinzhou

🏠
Working from home
View GitHub Profile
package models
type Tag struct {
Model
Name string `json:"name"`
CreatedBy string `json:"created_by"`
ModifiedBy string `json:"modified_by"`
State int `json:"state"`
}
package main
import (
"fmt"
"log"
"net/http"
"github.com/gavinzhou/hello-gin/pkg/setting"
"github.com/gin-gonic/gin"
)
package models
import (
"fmt"
"log"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/postgres"
"github.com/gavinzhou/hello-gin/pkg/setting"
package util
import (
"github.com/Unknwon/com"
"github.com/gin-gonic/gin"
"github.com/gavinzhou/hello-gin/pkg/setting"
)
func GetPage(c *gin.Context) int {
package e
var MsgFlags = map[int]string{
SUCCESS: "ok",
ERROR: "fail",
INVALID_PARAMS: "invalid params",
ERROR_EXIST_TAG: "tag is exist",
ERROR_NOT_EXIST_TAG: "tag is not exist",
ERROR_NOT_EXIST_ARTICLE: "article is not exist",
ERROR_AUTH_CHECK_TOKEN_FAIL: "token check is fail",
package e
const (
SUCCESS = 200
ERROR = 500
INVALID_PARAMS = 400
ERROR_EXIST_TAG = 10001
ERROR_NOT_EXIST_TAG = 10002
ERROR_NOT_EXIST_ARTICLE = 10003
package setting
import (
"time"
"github.com/kelseyhightower/envconfig"
)
type DBConfig struct {
DBHost string `envconfig:"DBHost"`
$ curl -s localhost:2379/v2/keys/registry/example.com/databases/default | jq .
{
"action": "get",
"node": {
"key": "/registry/example.com/databases/default",
"dir": true,
"nodes": [
{
"key": "/registry/example.com/databases/default/wordpress",
"value": "{\"apiVersion\":\"example.com/v1\",\"kind\":\"Database\",\"metadata\":{\"clusterName\":\"\",\"creationTimestamp\":\"2017-08-09T14:53:40Z\",\"deletionGracePeriodSeconds\":null,\"deletionTimestamp\":null,\"name\":\"wordpress\",\"namespace\":\"default\",\"selfLink\":\"\",\"uid\":\"8837f788-7d12-11e7-9d28-080027390640\"},\"spec\":{\"encoding\":\"unicode\",\"password\":\"secret\",\"user\":\"wp\"}}\n",
$ http 127.0.0.1:8001/apis/example.com/v1/namespaces/default/databases
HTTP/1.1 200 OK
Content-Length: 593
Content-Type: application/json
Date: Wed, 09 Aug 2017 09:38:49 GMT
{
"apiVersion": "example.com/v1",
"items": [
{
$ cat wordpress-database.yaml
apiVersion: example.com/v1
kind: Database
metadata:
name: wordpress
spec:
user: wp
password: secret
encoding: unicode