├── .gitignore ├── .travis.yml ├── Dockerfile ├── Gopkg.lock ├── Gopkg.toml ├── Jenkinsfile.kubesphere ├── LICENSE ├── Makefile ├── README.md ├── api └── api.yaml ├── build └── docker │ └── Dockerfile ├── deploy ├── apiserver │ ├── apiserver-svc.yaml │ └── apiserver.yaml ├── ctrl │ └── devops-db-ctrl-job.yaml └── init │ └── db-init-job.yaml ├── hack ├── build-go.sh ├── build-image.sh ├── docker_push.sh ├── fmt.sh ├── util.sh ├── verify-goimports.sh └── verify.sh ├── pkg ├── config │ ├── config.go │ ├── env_loader.go │ └── test_config │ │ └── config.go ├── constants │ └── commom.go ├── db │ ├── Dockerfile │ ├── condition.go │ ├── condition_test.go │ ├── connection.go │ ├── db.go │ ├── ddl │ │ └── devops.sql │ ├── error.go │ ├── event.go │ ├── schema │ │ └── devops │ │ │ ├── V0_1__init.sql │ │ │ └── V0_2__credential.sql │ └── scripts │ │ └── ddl_init.sh ├── ds │ └── ds.go ├── gojenkins │ ├── README.md │ ├── _tests │ │ ├── build_history.txt │ │ └── job.xml │ ├── artifact.go │ ├── build.go │ ├── build_history.go │ ├── constants.go │ ├── credential.go │ ├── executor.go │ ├── fingerprint.go │ ├── folder.go │ ├── jenkins.go │ ├── job.go │ ├── label.go │ ├── node.go │ ├── pipeline_model_converter.go │ ├── plugin.go │ ├── queue.go │ ├── request.go │ ├── role.go │ ├── utils.go │ └── views.go ├── logger │ ├── logger.go │ └── logger_test.go ├── models │ ├── common.go │ ├── credential.go │ ├── membership.go │ └── project.go ├── server │ └── main.go ├── service │ ├── projects │ │ ├── pipeline_sonar_handler.go │ │ ├── project_credential.go │ │ ├── project_credential_handler.go │ │ ├── project_handler.go │ │ ├── project_member_handler.go │ │ ├── project_pipeline.go │ │ ├── project_pipeline_handler.go │ │ ├── project_pipeline_test.go │ │ └── projects.go │ ├── router.go │ └── server.go └── utils │ ├── idutils │ ├── id_utils.go │ └── id_utils_test.go │ ├── reflectutils │ └── reflect.go │ ├── stringutils │ └── string.go │ └── userutils │ └── user.go ├── sonar-project.properties └── vendor ├── github.com ├── BurntSushi │ └── toml │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── COMPATIBLE │ │ ├── COPYING │ │ ├── Makefile │ │ ├── README.md │ │ ├── cmd │ │ ├── toml-test-decoder │ │ │ └── COPYING │ │ ├── toml-test-encoder │ │ │ └── COPYING │ │ └── tomlv │ │ │ └── COPYING │ │ ├── decode.go │ │ ├── decode_meta.go │ │ ├── doc.go │ │ ├── encode.go │ │ ├── encoding_types.go │ │ ├── encoding_types_1.1.go │ │ ├── lex.go │ │ ├── parse.go │ │ ├── session.vim │ │ ├── type_check.go │ │ └── type_fields.go ├── PuerkitoBio │ └── goquery │ │ ├── .gitattributes │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── README.md │ │ ├── array.go │ │ ├── doc.go │ │ ├── expand.go │ │ ├── filter.go │ │ ├── go.mod │ │ ├── go.sum │ │ ├── iteration.go │ │ ├── manipulation.go │ │ ├── property.go │ │ ├── query.go │ │ ├── traversal.go │ │ ├── type.go │ │ └── utilities.go ├── andybalholm │ └── cascadia │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── README.md │ │ ├── go.mod │ │ ├── parser.go │ │ └── selector.go ├── ant0ine │ └── go-json-rest │ │ ├── LICENSE │ │ └── rest │ │ ├── access_log_apache.go │ │ ├── access_log_json.go │ │ ├── api.go │ │ ├── auth_basic.go │ │ ├── content_type_checker.go │ │ ├── cors.go │ │ ├── doc.go │ │ ├── gzip.go │ │ ├── if.go │ │ ├── json_indent.go │ │ ├── jsonp.go │ │ ├── middleware.go │ │ ├── powered_by.go │ │ ├── recorder.go │ │ ├── recover.go │ │ ├── request.go │ │ ├── response.go │ │ ├── route.go │ │ ├── router.go │ │ ├── status.go │ │ ├── timer.go │ │ └── trie │ │ └── impl.go ├── asaskevich │ └── govalidator │ │ ├── .travis.yml │ │ ├── CONTRIBUTING.md │ │ ├── LICENSE │ │ ├── README.md │ │ ├── arrays.go │ │ ├── converter.go │ │ ├── error.go │ │ ├── numerics.go │ │ ├── patterns.go │ │ ├── types.go │ │ ├── utils.go │ │ ├── validator.go │ │ └── wercker.yml ├── beevik │ └── etree │ │ ├── .travis.yml │ │ ├── CONTRIBUTORS │ │ ├── LICENSE │ │ ├── README.md │ │ ├── RELEASE_NOTES.md │ │ ├── etree.go │ │ ├── helpers.go │ │ └── path.go ├── davecgh │ └── go-spew │ │ ├── LICENSE │ │ └── spew │ │ ├── bypass.go │ │ ├── bypasssafe.go │ │ ├── common.go │ │ ├── config.go │ │ ├── doc.go │ │ ├── dump.go │ │ ├── format.go │ │ └── spew.go ├── fatih │ ├── camelcase │ │ ├── .travis.yml │ │ ├── LICENSE.md │ │ ├── README.md │ │ └── camelcase.go │ └── structs │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── README.md │ │ ├── field.go │ │ ├── structs.go │ │ └── tags.go ├── go-sql-driver │ └── mysql │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── AUTHORS │ │ ├── CHANGELOG.md │ │ ├── CONTRIBUTING.md │ │ ├── LICENSE │ │ ├── README.md │ │ ├── appengine.go │ │ ├── auth.go │ │ ├── buffer.go │ │ ├── collations.go │ │ ├── connection.go │ │ ├── connection_go18.go │ │ ├── const.go │ │ ├── driver.go │ │ ├── dsn.go │ │ ├── errors.go │ │ ├── fields.go │ │ ├── infile.go │ │ ├── packets.go │ │ ├── result.go │ │ ├── rows.go │ │ ├── statement.go │ │ ├── transaction.go │ │ ├── utils.go │ │ ├── utils_go17.go │ │ └── utils_go18.go ├── gocraft │ └── dbr │ │ ├── CHANGELOG.md │ │ ├── LICENSE │ │ ├── README.md │ │ ├── buffer.go │ │ ├── builder.go │ │ ├── condition.go │ │ ├── dbr.go │ │ ├── delete.go │ │ ├── delete_builder.go │ │ ├── dialect.go │ │ ├── dialect │ │ ├── dialect.go │ │ ├── mysql.go │ │ ├── postgresql.go │ │ └── sqlite3.go │ │ ├── errors.go │ │ ├── event.go │ │ ├── expr.go │ │ ├── ident.go │ │ ├── insert.go │ │ ├── insert_builder.go │ │ ├── interpolate.go │ │ ├── join.go │ │ ├── load.go │ │ ├── now.go │ │ ├── order.go │ │ ├── select.go │ │ ├── select_builder.go │ │ ├── select_return.go │ │ ├── transaction.go │ │ ├── types.go │ │ ├── union.go │ │ ├── update.go │ │ ├── update_builder.go │ │ └── util.go ├── golang │ ├── example │ │ ├── LICENSE │ │ └── stringutil │ │ │ └── reverse.go │ └── glog │ │ ├── LICENSE │ │ ├── README │ │ ├── glog.go │ │ └── glog_file.go ├── google │ └── go-querystring │ │ ├── LICENSE │ │ └── query │ │ └── encode.go ├── koding │ └── multiconfig │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── README.md │ │ ├── doc.go │ │ ├── env.go │ │ ├── file.go │ │ ├── flag.go │ │ ├── multiconfig.go │ │ ├── multiloader.go │ │ ├── multivalidator.go │ │ ├── tag.go │ │ └── validator.go ├── kubesphere │ └── sonargo │ │ ├── LICENSE │ │ └── sonar │ │ ├── ce_service.go │ │ ├── client.go │ │ ├── client_util.go │ │ ├── components_service.go │ │ ├── duplications_service.go │ │ ├── favorites_service.go │ │ ├── issues_service.go │ │ ├── languages_service.go │ │ ├── measures_service.go │ │ ├── metrics.go │ │ ├── metrics_service.go │ │ ├── notifications_service.go │ │ ├── permissions_service.go │ │ ├── plugins_service.go │ │ ├── project_analyses_service.go │ │ ├── project_badges_service.go │ │ ├── project_branches_service.go │ │ ├── project_links_service.go │ │ ├── project_pull_requests_service.go │ │ ├── project_tags_service.go │ │ ├── projects_service.go │ │ ├── qualitygates_service.go │ │ ├── qualityprofiles_service.go │ │ ├── rules_service.go │ │ ├── server_service.go │ │ ├── settings_service.go │ │ ├── sonarqube.go │ │ ├── sources_service.go │ │ ├── system_service.go │ │ ├── user_groups_service.go │ │ ├── user_tokens_service.go │ │ ├── users_service.go │ │ ├── validation.go │ │ └── webhooks_service.go ├── mitchellh │ └── mapstructure │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── README.md │ │ ├── decode_hooks.go │ │ ├── error.go │ │ ├── go.mod │ │ └── mapstructure.go ├── pmezard │ └── go-difflib │ │ ├── LICENSE │ │ └── difflib │ │ └── difflib.go ├── sony │ └── sonyflake │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── README.md │ │ └── sonyflake.go ├── speps │ └── go-hashids │ │ ├── .editorconfig │ │ ├── .gitignore │ │ ├── LICENSE │ │ ├── README.md │ │ └── hashids.go └── stretchr │ └── testify │ ├── LICENSE │ └── assert │ ├── assertion_format.go │ ├── assertion_format.go.tmpl │ ├── assertion_forward.go │ ├── assertion_forward.go.tmpl │ ├── assertions.go │ ├── doc.go │ ├── errors.go │ ├── forward_assertions.go │ └── http_assertions.go ├── golang.org └── x │ └── net │ ├── AUTHORS │ ├── CONTRIBUTORS │ ├── LICENSE │ ├── PATENTS │ └── html │ ├── atom │ ├── atom.go │ ├── gen.go │ └── table.go │ ├── const.go │ ├── doc.go │ ├── doctype.go │ ├── entity.go │ ├── escape.go │ ├── foreign.go │ ├── node.go │ ├── parse.go │ ├── render.go │ └── token.go ├── google.golang.org └── appengine │ ├── LICENSE │ └── cloudsql │ ├── cloudsql.go │ ├── cloudsql_classic.go │ └── cloudsql_vm.go └── gopkg.in └── yaml.v2 ├── .travis.yml ├── LICENSE ├── LICENSE.libyaml ├── NOTICE ├── README.md ├── apic.go ├── decode.go ├── emitterc.go ├── encode.go ├── go.mod ├── parserc.go ├── readerc.go ├── resolve.go ├── scannerc.go ├── sorter.go ├── writerc.go ├── yaml.go ├── yamlh.go └── yamlprivateh.go /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Example user template template 3 | ### Example user template 4 | 5 | # IntelliJ project files 6 | .idea 7 | *.iml 8 | out 9 | gen### Go template 10 | # Binaries for programs and plugins 11 | *.exe 12 | *.exe~ 13 | *.dll 14 | *.so 15 | *.dylib 16 | 17 | # Test binary, build with `go test -c` 18 | *.test 19 | 20 | # Output of the go coverage tool, specifically when used with LiteIDE 21 | *.out 22 | cmd/server 23 | 24 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go_import_path: kubesphere.io/devops 4 | 5 | go: 6 | - "1.10.3" 7 | 8 | sudo: required 9 | 10 | services: 11 | - docker 12 | 13 | before_script: 14 | - docker --version 15 | 16 | install: 17 | - chmod +x hack/*.sh 18 | - go get golang.org/x/tools/cmd/goimports 19 | 20 | script: 21 | - make test 22 | 23 | deploy: 24 | - provider: script 25 | script: bash hack/docker_push.sh advanced-2.0.0-dev 26 | on: 27 | branch: master 28 | repo: kubesphere/devops 29 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.10.1-alpine3.7 as builder 2 | WORKDIR /go/src/kubesphere.io/devops/ 3 | COPY . . 4 | 5 | RUN CGO_ENABLED=0 GOOS=linux go build -v -a -installsuffix cgo -ldflags '-w' -o cmd/ks-devops pkg/server/main.go 6 | 7 | 8 | 9 | FROM alpine 10 | COPY --from=builder /go/src/kubesphere.io/devops/cmd/* /usr/local/bin/ 11 | EXPOSE 8080 12 | CMD ["/usr/local/bin/ks-devops"] 13 | -------------------------------------------------------------------------------- /Gopkg.toml: -------------------------------------------------------------------------------- 1 | [prune] 2 | go-tests = true 3 | unused-packages = true 4 | 5 | [[constraint]] 6 | name = "github.com/kubesphere/sonargo" 7 | version = "0.0.2" 8 | -------------------------------------------------------------------------------- /Jenkinsfile.kubesphere: -------------------------------------------------------------------------------- 1 | pipeline { 2 | agent { 3 | node{ 4 | label 'go' 5 | } 6 | } 7 | stages { 8 | stage('unit test'){ 9 | steps{ 10 | container('go'){ 11 | sh 'mkdir -p /home/jenkins/go/src/kubesphere.io' 12 | sh "ln -s -f `pwd` /home/jenkins/go/src/kubesphere.io/devops" 13 | sh 'cd /home/jenkins/go/src/kubesphere.io/devops && make test' 14 | } 15 | } 16 | } 17 | stage('sonarqube analysis'){ 18 | steps{ 19 | script { 20 | scannerHome = tool 'sonar'; 21 | } 22 | withCredentials([string(credentialsId: 'sonar-token', variable: 'SONAR_TOKEN')]) { 23 | withSonarQubeEnv('sonar') { 24 | sh "${scannerHome}/bin/sonar-scanner -Dsonar.branch=$BRANCH_NAME -Dsonar.projectKey=ks-devops -Dsonar.sources=. -Dsonar.login=$SONAR_TOKEN" 25 | } 26 | } 27 | timeout(time: 1, unit: 'HOURS') { 28 | waitForQualityGate abortPipeline: true 29 | } 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | TAG=$(tag) 2 | TEST?=$$(go list ./... |grep -v 'vendor') 3 | 4 | .PHONY: test build clean check build-flyway 5 | check: 6 | hack/verify.sh 7 | fmt: 8 | hack/fmt.sh -l 9 | fmt-all: 10 | hack/fmt.sh -a 11 | build: 12 | hack/build-go.sh 13 | local-run: 14 | hack/run-local-go.sh 15 | image: 16 | hack/build-image.sh $(TAG) 17 | clean: 18 | rm -rf cmd/server 19 | test: 20 | go test $(TEST) -v -timeout 120m -coverprofile=test_coverage.out 21 | 22 | 23 | build-image-%: ## build docker image 24 | @if [ "$*" = "latest" ];then \ 25 | docker build -t kubesphere/devops:latest .; \ 26 | docker build -t kubesphere/devops:flyway -f ./pkg/db/Dockerfile ./pkg/db/;\ 27 | elif [ "`echo "$*" | grep -E "^v[0-9]+\.[0-9]+\.[0-9]+"`" != "" ];then \ 28 | docker build -t kubesphere/devops:$* .; \ 29 | docker build -t kubesphere/devops:flyway-$* -f ./pkg/db/Dockerfile ./pkg/db/; \ 30 | fi 31 | 32 | push-image-%: ## push docker image 33 | @if [ "$*" = "latest" ];then \ 34 | docker push kubesphere/devops:latest; \ 35 | docker push kubesphere/devops:flyway; \ 36 | elif [ "`echo "$*" | grep -E "^v[0-9]+\.[0-9]+\.[0-9]+"`" != "" ];then \ 37 | docker push kubesphere/devops:$*; \ 38 | docker push kubesphere/devops:flyway-$*; \ 39 | fi 40 | 41 | build-dev-image-%: 42 | @if [ "$*" = "latest" ];then \ 43 | docker build -t kubespheredev/ks-devops:latest .; \ 44 | docker build -t kubespheredev/ks-devops:flyway -f ./pkg/db/Dockerfile ./pkg/db/;\ 45 | elif [ "`echo "$*" `" != "" ];then \ 46 | docker build -t kubespheredev/ks-devops:$* .; \ 47 | docker build -t kubespheredev/ks-devops:flyway-$* -f ./pkg/db/Dockerfile ./pkg/db/; \ 48 | fi 49 | 50 | push-dev-image-%: 51 | @if [ "$*" = "latest" ];then \ 52 | docker push kubespheredev/ks-devops:latest; \ 53 | docker push kubespheredev/ks-devops:flyway; \ 54 | elif [ "`echo "$*" `" != "" ];then \ 55 | docker push kubespheredev/ks-devops:$*; \ 56 | docker push kubespheredev/ks-devops:flyway-$*; \ 57 | fi 58 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Welcome To DevOPSphere 2 | -------------------------------------------------------------------------------- /build/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.10.1-alpine3.7 as builder 2 | WORKDIR /go/src/kubesphere.io/devops/ 3 | COPY . . 4 | 5 | RUN CGO_ENABLED=0 GOOS=linux go build -v -a -installsuffix cgo -ldflags '-w' -o cmd/ks-devops pkg/server/main.go 6 | 7 | 8 | 9 | FROM alpine 10 | COPY --from=builder /go/src/kubesphere.io/devops/cmd/* /usr/local/bin/ 11 | EXPOSE 8080 12 | CMD ["/usr/local/bin/ks-devops"] 13 | -------------------------------------------------------------------------------- /deploy/apiserver/apiserver-svc.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: ks-devops-apiserver 5 | annotations: 6 | desc: '' 7 | namespace: kubesphere-devops-system 8 | labels: 9 | app: ks-devops-apiserver 10 | spec: 11 | selector: 12 | app: ks-devops-apiserver 13 | ports: 14 | - name: http 15 | port: 80 16 | targetPort: 8080 17 | protocol: TCP 18 | sessionAffinity: None 19 | -------------------------------------------------------------------------------- /deploy/apiserver/apiserver.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: ks-devops-apiserver 5 | namespace: kubesphere-devops-system 6 | labels: 7 | app: ks-devops-apiserver 8 | spec: 9 | selector: 10 | matchLabels: 11 | app: ks-devops-apiserver 12 | replicas: 1 13 | template: 14 | metadata: 15 | labels: 16 | app: ks-devops-apiserver 17 | spec: 18 | containers: 19 | - image: kubesphere/devops:latest 20 | imagePullPolicy: Always 21 | name: devops 22 | env: 23 | - name: DEVOPSPHERE_MYSQL_USERNAME 24 | value: "root" 25 | - name: DEVOPSPHERE_MYSQL_PASSWORD 26 | value: "password" 27 | - name: DEVOPSPHERE_MYSQL_DATABASE 28 | value: "devops" 29 | - name: DEVOPSPHERE_JENKINS_ADDRESS 30 | value: "http://jenkins.kube-devops.svc/" 31 | - name: DEVOPSPHERE_JENKINS_USER 32 | value: "admin" 33 | - name: DEVOPSPHERE_JENKINS_PASSWORD 34 | value: "password" 35 | - name: DEVOPSPHERE_MYSQL_HOST 36 | value: "openpitrix-db.openpitrix-system.svc" 37 | - name: DEVOPSPHERE_MYSQL_PORT 38 | value: "3306" 39 | - name: DEVOPSPHERE_IP 40 | valueFrom: 41 | fieldRef: 42 | fieldPath: status.podIP 43 | ports: 44 | - containerPort: 8080 45 | -------------------------------------------------------------------------------- /deploy/ctrl/devops-db-ctrl-job.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: batch/v1 2 | kind: Job 3 | metadata: 4 | name: ks-devops-db-ctrl-job 5 | namespace: kubesphere-devops-system 6 | labels: 7 | app: ks-devops-apiserver 8 | job: ks-devops-db-ctrl 9 | version: latest 10 | spec: 11 | backoffLimit: 6 12 | completions: 1 13 | parallelism: 1 14 | template: 15 | metadata: 16 | labels: 17 | app: ks-devops-apiserver 18 | job: ks-devops-db-ctrl 19 | version: latest 20 | name: ks-devops-db-ctrl 21 | spec: 22 | initContainers: 23 | - name: wait-mysql 24 | image: busybox:1.28.4 25 | imagePullPolicy: IfNotPresent 26 | command: ['sh', '-c', 'until nc -z openpitrix-db.openpitrix-system.svc 3306; do echo "waiting for mysql"; sleep 2; done;'] 27 | containers: 28 | - command: ["flyway", "-X", "-url=jdbc:mysql://openpitrix-db.openpitrix-system.svc/devops", "-user=root", "-validateOnMigrate=false", "-locations=filesystem:/flyway/sql/devops", "migrate"] 29 | env: 30 | - name: FLYWAY_PASSWORD 31 | value: "password" 32 | image: kubesphere/devops:flyway 33 | imagePullPolicy: Always 34 | name: devops-db-ctrl 35 | resources: {} 36 | terminationMessagePath: /dev/termination-log 37 | terminationMessagePolicy: File 38 | dnsPolicy: ClusterFirst 39 | restartPolicy: OnFailure 40 | schedulerName: default-scheduler 41 | securityContext: {} 42 | terminationGracePeriodSeconds: 30 43 | -------------------------------------------------------------------------------- /deploy/init/db-init-job.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: batch/v1 2 | kind: Job 3 | metadata: 4 | name: ks-devops-db-init-job 5 | namespace: kubesphere-devops-system 6 | labels: 7 | app: ks-devops-apiserver 8 | job: ks-devops-db-init 9 | version: latest 10 | spec: 11 | backoffLimit: 6 12 | completions: 1 13 | parallelism: 1 14 | template: 15 | metadata: 16 | labels: 17 | app: ks-devops-apiserver 18 | job: ks-devops-db-init 19 | version: latest 20 | name: ks-devops-db-init 21 | spec: 22 | initContainers: 23 | - name: wait-mysql 24 | image: busybox:1.28.4 25 | imagePullPolicy: IfNotPresent 26 | command: ['sh', '-c', 'until nc -z openpitrix-db.openpitrix-system.svc 3306; do echo "waiting for mysql"; sleep 2; done;'] 27 | containers: 28 | - command: ["/flyway/sql/ddl/ddl_init.sh", "-hopenpitrix-db.openpitrix-system.svc", "-uroot", "--connect-timeout=5"] 29 | env: 30 | - name: PASSWORD 31 | value: "password" 32 | image: kubesphere/devops:flyway 33 | imagePullPolicy: Always 34 | name: devops-db-init 35 | resources: {} 36 | terminationMessagePath: /dev/termination-log 37 | terminationMessagePolicy: File 38 | dnsPolicy: ClusterFirst 39 | restartPolicy: OnFailure 40 | schedulerName: default-scheduler 41 | securityContext: {} 42 | terminationGracePeriodSeconds: 30 43 | -------------------------------------------------------------------------------- /hack/build-go.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -o errexit 4 | set -o nounset 5 | set -o pipefail 6 | 7 | ROOT=$(dirname $BASH_SOURCE)/.. 8 | 9 | cd $ROOT 10 | 11 | CGO_ENABLED=0 GOOS=linux go build -v -a -installsuffix cgo -ldflags '-w' -o cmd/server pkg/server/main.go 12 | 13 | -------------------------------------------------------------------------------- /hack/build-image.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | set -o errexit 5 | set -o nounset 6 | set -o pipefail 7 | 8 | ROOT=$(dirname $BASH_SOURCE)/.. 9 | 10 | cd $ROOT 11 | if [ $# -lt 1 ]; then 12 | echo "Please enter the name of image" 13 | exit 1 14 | fi 15 | 16 | IMAGE_NAME=$1 17 | docker build -t $IMAGE_NAME -f build/docker/Dockerfile . 18 | 19 | 20 | -------------------------------------------------------------------------------- /hack/docker_push.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | Version=$1 4 | 5 | make build-dev-image-${Version} 6 | echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin 7 | make push-dev-image-${Version} 8 | -------------------------------------------------------------------------------- /hack/fmt.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -o nounset 4 | set -o pipefail 5 | 6 | ROOT=$(dirname "${BASH_SOURCE}")/.. 7 | source "${ROOT}/hack/util.sh" 8 | cd "${ROOT}" 9 | 10 | type goimports >/dev/null 2>&1|| { echo "goimports is required. Please install it by `go get golang.org/x/tools/cmd/goimports`"; exit 1;} 11 | 12 | USAGE="Please specify -a (format all go files) or -d (format files changed between current commit and last commit) or -l (format files changed locally)" 13 | if [ $# -gt 0 ]; then 14 | case $1 in 15 | -d|--diff) 16 | echo "Format files between commits......." 17 | bad_files=$(util::find_diff_files) 18 | ;; 19 | -a|--all) 20 | echo "Format all files......" 21 | bad_files=$(util::find_files) 22 | ;; 23 | -l|--local) 24 | echo "Format local changed files......" 25 | bad_files=$(util::find_local_change_files) 26 | ;; 27 | *) 28 | echo "$USAGE" 29 | exit 1 30 | ;; 31 | esac 32 | else 33 | echo "$USAGE" 34 | exit 1 35 | fi 36 | 37 | if [ -z $bad_files ]; then 38 | echo "No go files need to format. DONE" 39 | exit 0 40 | fi 41 | for file in $bad_files 42 | do 43 | echo "Processing ::$file" 44 | goimports -l -w -e -local=kubesphere $file 45 | done 46 | 47 | if [ $? -ne 0 ]; then 48 | echo "Cannot to format source codes, Please check it manualy " 49 | exit 1 50 | fi 51 | echo "Format is DONE" 52 | 53 | -------------------------------------------------------------------------------- /hack/util.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Provides simple utility functions 4 | 5 | # Handler for when we exit automatically on an error. 6 | # Borrowed from https://gist.github.com/ahendrix/7030300 7 | log::errexit() { 8 | local err="${PIPESTATUS[@]}" 9 | 10 | # If the shell we are in doesn't have errexit set (common in subshells) then 11 | # don't dump stacks. 12 | set +o | grep -qe "-o errexit" || return 13 | 14 | set +o xtrace 15 | local code="${1:-1}" 16 | log::error_exit "'${BASH_COMMAND}' exited with status $err" "${1:-1}" 1 17 | } 18 | 19 | log::install_errexit() { 20 | # trap ERR to provide an error handler whenever a command exits nonzero this 21 | # is a more verbose version of set -o errexit 22 | trap 'log::errexit' ERR 23 | 24 | # setting errtrace allows our ERR trap handler to be propagated to functions, 25 | # expansions and subshells 26 | set -o errtrace 27 | } 28 | 29 | # Print out the stack trace 30 | # 31 | # Args: 32 | # $1 The number of stack frames to skip when printing. 33 | log::stack() { 34 | local stack_skip=${1:-0} 35 | stack_skip=$((stack_skip + 1)) 36 | if [[ ${#FUNCNAME[@]} -gt $stack_skip ]]; then 37 | echo "Call stack:" >&2 38 | local i 39 | for ((i=1 ; i <= ${#FUNCNAME[@]} - $stack_skip ; i++)) 40 | do 41 | local frame_no=$((i - 1 + stack_skip)) 42 | local source_file=${BASH_SOURCE[$frame_no]} 43 | local source_lineno=${BASH_LINENO[$((frame_no - 1))]} 44 | local funcname=${FUNCNAME[$frame_no]} 45 | echo " $i: ${source_file}:${source_lineno} ${funcname}(...)" >&2 46 | done 47 | fi 48 | } 49 | 50 | # Log an error and exit. 51 | # Args: 52 | # $1 Message to log with the error 53 | # $2 The error code to return 54 | # $3 The number of stack frames to skip when printing. 55 | log::error_exit() { 56 | local message="${1:-}" 57 | local code="${2:-1}" 58 | local stack_skip="${3:-0}" 59 | stack_skip=$((stack_skip + 1)) 60 | 61 | local source_file=${BASH_SOURCE[$stack_skip]} 62 | local source_line=${BASH_LINENO[$((stack_skip - 1))]} 63 | echo "!!! Error in ${source_file}:${source_line}" >&2 64 | [[ -z ${1-} ]] || { 65 | echo " ${1}" >&2 66 | } 67 | 68 | log::stack $stack_skip 69 | 70 | echo "Exiting with status ${code}" >&2 71 | exit "${code}" 72 | } 73 | 74 | util::sed() { 75 | if [[ "$(go env GOHOSTOS)" == "darwin" ]]; then 76 | sed -i '' $@ 77 | else 78 | sed -i'' $@ 79 | fi 80 | } 81 | 82 | util::find_files() { 83 | find . -type d -name vendor -prune -o -name '*.go' -print 84 | } 85 | 86 | util::find_diff_files(){ 87 | git diff --name-only --diff-filter=ad HEAD^ HEAD | grep -E "^(test|cmd|pkg)/.+\.go" 88 | } 89 | 90 | util::find_local_change_files(){ 91 | git diff --name-only --diff-filter=ad | grep -E "^(test|cmd|pkg)/.+\.go" 92 | } 93 | 94 | -------------------------------------------------------------------------------- /hack/verify-goimports.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -o nounset 4 | set -o pipefail 5 | set -o errexit 6 | echo $(go version) 7 | 8 | ROOT=$(dirname "${BASH_SOURCE}")/.. 9 | source "${ROOT}/hack/util.sh" 10 | cd "${ROOT}" 11 | 12 | type goimports >/dev/null 2>&1|| { echo "goimports is required. Please install it by `go get golang.org/x/tools/cmd/goimports`"; exit 1;} 13 | 14 | set +e 15 | if [ $# -gt 0 ]; then 16 | case $1 in 17 | -d|--diff) 18 | echo "Verify files changed......" 19 | 20 | bad_files=$(util::find_diff_files) 21 | set -e 22 | ;; 23 | -a|--all) 24 | echo "Verify all files......" 25 | bad_files=$(util::find_files) 26 | ;; 27 | *) 28 | echo "Please specify -a (verify all go files) or -d (verify diff only)" 29 | exit 1 30 | ;; 31 | esac 32 | else 33 | echo "Please specify -a (verify all go files) or -d (verify diff only)" 34 | exit 1 35 | fi 36 | set -e 37 | 38 | if [ -z "$bad_files" ]; then 39 | echo "No go files need to check. PASS" 40 | exit 0 41 | fi 42 | 43 | bad_files=$(echo -e $bad_files| xargs goimports -l -e -local=kubesphere ) 44 | if [[ -n "${bad_files}" ]]; then 45 | echo "The imports of following files should be formated: " 46 | echo "${bad_files}" 47 | echo "Try running 'goimports -l -w -e -local=kubesphere [path]'" 48 | exit 1 49 | fi 50 | echo "goimports verify PASS" 51 | 52 | -------------------------------------------------------------------------------- /hack/verify.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -o errexit 4 | set -o nounset 5 | set -o pipefail 6 | 7 | ROOT=$(dirname "${BASH_SOURCE}") 8 | cd $ROOT 9 | 10 | ./verify-goimports.sh -a 11 | 12 | echo "ALL PASS" 13 | 14 | -------------------------------------------------------------------------------- /pkg/config/config.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The KubeSphere Authors. 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | 14 | package config 15 | 16 | import ( 17 | "flag" 18 | "fmt" 19 | "os" 20 | 21 | "github.com/koding/multiconfig" 22 | 23 | "kubesphere.io/devops/pkg/logger" 24 | ) 25 | 26 | type Config struct { 27 | Log LogConfig 28 | Mysql MysqlConfig 29 | Jenkins JenkinsConfig 30 | Sonar SonarConfig 31 | } 32 | 33 | type LogConfig struct { 34 | Level string `default:"info"` // debug, info, warn, error, fatal 35 | } 36 | 37 | type MysqlConfig struct { 38 | Host string `default:"kubesphere-db"` 39 | Port string `default:"3306"` 40 | User string `default:"root"` 41 | Password string `default:"password"` 42 | Database string `default:"kubesphere"` 43 | } 44 | 45 | type JenkinsConfig struct { 46 | Address string `default:"http://jenkins.kubesphere.com/"` 47 | User string `default:"magicsong"` 48 | Password string `default:"devops"` 49 | MaxConn string `default:"20"` 50 | } 51 | 52 | type SonarConfig struct { 53 | Address string `default:""` 54 | Token string `default:""` 55 | } 56 | 57 | func (m *MysqlConfig) GetUrl() string { 58 | return fmt.Sprintf("%s:%s@tcp(%s:%s)/%s", m.User, m.Password, m.Host, m.Port, m.Database) 59 | } 60 | 61 | func PrintUsage() { 62 | flag.PrintDefaults() 63 | fmt.Fprint(os.Stdout, "\nSupported environment variables:\n") 64 | e := newLoader("devopsphere") 65 | e.PrintEnvs(new(Config)) 66 | fmt.Println("") 67 | } 68 | 69 | func GetFlagSet() *flag.FlagSet { 70 | flag.CommandLine.Usage = PrintUsage 71 | return flag.CommandLine 72 | } 73 | 74 | func ParseFlag() { 75 | GetFlagSet().Parse(os.Args[1:]) 76 | } 77 | 78 | var profilingServerStarted = false 79 | 80 | func LoadConf() *Config { 81 | ParseFlag() 82 | 83 | config := new(Config) 84 | m := &multiconfig.DefaultLoader{} 85 | m.Loader = multiconfig.MultiLoader(newLoader("devopsphere")) 86 | m.Validator = multiconfig.MultiValidator( 87 | &multiconfig.RequiredValidator{}, 88 | ) 89 | err := m.Load(config) 90 | if err != nil { 91 | panic(err) 92 | } 93 | logger.SetLevelByString(config.Log.Level) 94 | logger.Info("LoadConf: %+v", config) 95 | 96 | return config 97 | } 98 | -------------------------------------------------------------------------------- /pkg/config/test_config/config.go: -------------------------------------------------------------------------------- 1 | package test_config 2 | 3 | import ( 4 | "os" 5 | "testing" 6 | 7 | "kubesphere.io/devops/pkg/config" 8 | "kubesphere.io/devops/pkg/db" 9 | "kubesphere.io/devops/pkg/logger" 10 | ) 11 | 12 | type DbTestConfig struct { 13 | openDbUnitTests string 14 | EnvConfig *config.Config 15 | } 16 | 17 | func NewDbTestConfig() DbTestConfig { 18 | tc := DbTestConfig{ 19 | openDbUnitTests: os.Getenv("KS_DEVOPS_DB_UNIT_TEST"), 20 | EnvConfig: config.LoadConf(), 21 | } 22 | return tc 23 | } 24 | 25 | func (tc DbTestConfig) GetDatabaseConn() *db.Database { 26 | if tc.openDbUnitTests == "1" { 27 | d, err := db.OpenDatabase(tc.EnvConfig.Mysql) 28 | if err != nil { 29 | logger.Critical("failed to open database %+v", tc.EnvConfig.Mysql) 30 | } 31 | return d 32 | } 33 | return nil 34 | } 35 | 36 | func (tc DbTestConfig) CheckDbUnitTest(t *testing.T) { 37 | if tc.openDbUnitTests != "1" { 38 | t.Skipf("if you want run unit tests with db,set KS_DEVOPS_DB_UNIT_TEST=1") 39 | } 40 | } 41 | 42 | type JenkinsTestConfig struct { 43 | openJenkinsUnitTests string 44 | EnvConfig *config.Config 45 | } 46 | 47 | func NewJenkinsTestConfig() JenkinsTestConfig { 48 | tc := JenkinsTestConfig{ 49 | openJenkinsUnitTests: os.Getenv("KS_DEVOPS_JK_UNIT_TEST"), 50 | EnvConfig: config.LoadConf(), 51 | } 52 | return tc 53 | } 54 | 55 | func (tc JenkinsTestConfig) CheckJenkinsUnitTest(t *testing.T) { 56 | if tc.openJenkinsUnitTests != "1" { 57 | t.Skipf("if you want run unit tests with db,set KS_DEVOPS_JK_UNIT_TEST=1") 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /pkg/constants/commom.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The KubeSphere Authors. 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | 14 | package constants 15 | 16 | const ( 17 | StatusActive = "active" 18 | StatusDeleted = "deleted" 19 | StatusDeleting = "deleting" 20 | StatusFailed = "failed" 21 | StatusPending = "pending" 22 | StatusWorking = "working" 23 | StatusSuccessful = "successful" 24 | ) 25 | 26 | const ( 27 | StatusColumn = "status" 28 | StatusTimeColumn = "status_time" 29 | ) 30 | 31 | const ( 32 | JenkinsAllUserRoleName = "kubesphere-user" 33 | ) 34 | 35 | const ( 36 | VisibilityPrivate = "private" 37 | VisibilityPublic = "public" 38 | ) 39 | 40 | const ( 41 | KS_ADMIN = "admin" 42 | ) 43 | -------------------------------------------------------------------------------- /pkg/db/Dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright 2017 The OpenPitrix Authors. All rights reserved. 2 | # Use of this source code is governed by a Apache license 3 | # that can be found in the LICENSE file. 4 | 5 | FROM dhoer/flyway:5.1.4-mysql-8.0.11-alpine 6 | 7 | RUN apk add --no-cache mysql-client 8 | 9 | COPY ./schema /flyway/sql 10 | COPY ./ddl /flyway/sql/ddl 11 | COPY ./scripts /flyway/sql/ddl 12 | -------------------------------------------------------------------------------- /pkg/db/condition_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The KubeSphere Authors. 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | 14 | package db 15 | 16 | import ( 17 | "testing" 18 | 19 | "github.com/gocraft/dbr" 20 | "github.com/gocraft/dbr/dialect" 21 | "github.com/stretchr/testify/assert" 22 | ) 23 | 24 | // Ref: https://github.com/gocraft/dbr/blob/5d59a8b3aa915660960329efb3af5513e7a0db07/condition_test.go 25 | func TestCondition(t *testing.T) { 26 | for _, test := range []struct { 27 | cond dbr.Builder 28 | query string 29 | value []interface{} 30 | }{ 31 | { 32 | cond: Eq("col", 1), 33 | query: "`col` = ?", 34 | value: []interface{}{1}, 35 | }, 36 | { 37 | cond: Eq("col", nil), 38 | query: "`col` IS NULL", 39 | value: nil, 40 | }, 41 | { 42 | cond: Eq("col", []int{}), 43 | query: "0", 44 | value: nil, 45 | }, 46 | { 47 | cond: Neq("col", 1), 48 | query: "`col` != ?", 49 | value: []interface{}{1}, 50 | }, 51 | { 52 | cond: Neq("col", nil), 53 | query: "`col` IS NOT NULL", 54 | value: nil, 55 | }, 56 | { 57 | cond: Gt("col", 1), 58 | query: "`col` > ?", 59 | value: []interface{}{1}, 60 | }, 61 | { 62 | cond: Gte("col", 1), 63 | query: "`col` >= ?", 64 | value: []interface{}{1}, 65 | }, 66 | { 67 | cond: Lt("col", 1), 68 | query: "`col` < ?", 69 | value: []interface{}{1}, 70 | }, 71 | { 72 | cond: Lte("col", 1), 73 | query: "`col` <= ?", 74 | value: []interface{}{1}, 75 | }, 76 | { 77 | cond: And(Lt("a", 1), Or(Gt("b", 2), Neq("c", 3))), 78 | query: "(`a` < ?) AND ((`b` > ?) OR (`c` != ?))", 79 | value: []interface{}{1, 2, 3}, 80 | }, 81 | } { 82 | buf := dbr.NewBuffer() 83 | err := test.cond.Build(dialect.MySQL, buf) 84 | assert.NoError(t, err) 85 | assert.Equal(t, test.query, buf.String()) 86 | assert.Equal(t, test.value, buf.Value()) 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /pkg/db/connection.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The KubeSphere Authors. 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | 14 | package db 15 | 16 | import ( 17 | "time" 18 | 19 | "github.com/gocraft/dbr" 20 | 21 | "kubesphere.io/devops/pkg/config" 22 | ) 23 | 24 | var defaultEventReceiver = EventReceiver{} 25 | 26 | func OpenDatabase(cfg config.MysqlConfig) (*Database, error) { 27 | // https://github.com/go-sql-driver/mysql/issues/9 28 | conn, err := dbr.Open("mysql", cfg.GetUrl()+"?parseTime=1&multiStatements=1&charset=utf8mb4&collation=utf8mb4_unicode_ci", &defaultEventReceiver) 29 | if err != nil { 30 | return nil, err 31 | } 32 | conn.SetMaxIdleConns(100) 33 | conn.SetMaxOpenConns(100) 34 | conn.SetConnMaxLifetime(10 * time.Second) 35 | return &Database{ 36 | Session: conn.NewSession(nil), 37 | }, nil 38 | } 39 | -------------------------------------------------------------------------------- /pkg/db/ddl/devops.sql: -------------------------------------------------------------------------------- 1 | CREATE DATABASE IF NOT EXISTS devops DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci; 2 | -------------------------------------------------------------------------------- /pkg/db/error.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The KubeSphere Authors. 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | 14 | package db 15 | 16 | import ( 17 | "github.com/gocraft/dbr" 18 | ) 19 | 20 | // package errors 21 | var ( 22 | ErrNotFound = dbr.ErrNotFound 23 | ErrNotSupported = dbr.ErrNotSupported 24 | ErrTableNotSpecified = dbr.ErrTableNotSpecified 25 | ErrColumnNotSpecified = dbr.ErrColumnNotSpecified 26 | ErrInvalidPointer = dbr.ErrInvalidPointer 27 | ErrPlaceholderCount = dbr.ErrPlaceholderCount 28 | ErrInvalidSliceLength = dbr.ErrInvalidSliceLength 29 | ErrCantConvertToTime = dbr.ErrCantConvertToTime 30 | ErrInvalidTimestring = dbr.ErrInvalidTimestring 31 | ) 32 | -------------------------------------------------------------------------------- /pkg/db/event.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The KubeSphere Authors. 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | 14 | package db 15 | 16 | import "kubesphere.io/devops/pkg/logger" 17 | 18 | // EventReceiver is a sentinel EventReceiver; use it if the caller doesn't supply one 19 | type EventReceiver struct{} 20 | 21 | // Event receives a simple notification when various events occur 22 | func (n *EventReceiver) Event(eventName string) { 23 | 24 | } 25 | 26 | // EventKv receives a notification when various events occur along with 27 | // optional key/value data 28 | func (n *EventReceiver) EventKv(eventName string, kvs map[string]string) { 29 | } 30 | 31 | // EventErr receives a notification of an error if one occurs 32 | func (n *EventReceiver) EventErr(eventName string, err error) error { 33 | return err 34 | } 35 | 36 | // EventErrKv receives a notification of an error if one occurs along with 37 | // optional key/value data 38 | func (n *EventReceiver) EventErrKv(eventName string, err error, kvs map[string]string) error { 39 | logger.Error("%+v", err) 40 | logger.Error("%s: %+v", eventName, kvs) 41 | return err 42 | } 43 | 44 | // Timing receives the time an event took to happen 45 | func (n *EventReceiver) Timing(eventName string, nanoseconds int64) { 46 | 47 | } 48 | 49 | // TimingKv receives the time an event took to happen along with optional key/value data 50 | func (n *EventReceiver) TimingKv(eventName string, nanoseconds int64, kvs map[string]string) { 51 | // TODO: Change logger level to debug 52 | logger.Debug("%s spend %.2fms: %+v", eventName, float32(nanoseconds)/1000000, kvs) 53 | } 54 | -------------------------------------------------------------------------------- /pkg/db/schema/devops/V0_1__init.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE project ( 2 | `project_id` VARCHAR(50) NOT NULL, 3 | `name` VARCHAR(50) NOT NULL, 4 | `description` TEXT NOT NULL, 5 | `creator` VARCHAR(50) NOT NULL, 6 | `create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, 7 | `status` VARCHAR(50) NOT NULL, 8 | `visibility` VARCHAR(50) NOT NULL, 9 | `extra` TEXT NOT NULL, 10 | PRIMARY KEY (`project_id`) 11 | ); 12 | 13 | 14 | 15 | CREATE TABLE `project_membership` ( 16 | `username` VARCHAR(50) NOT NULL, 17 | `project_id` VARCHAR(50) NOT NULL, 18 | `role` VARCHAR(50) NOT NULL, 19 | `status` VARCHAR(50) NOT NULL, 20 | `grant_by` VARCHAR(50) NOT NULL, 21 | PRIMARY KEY (`username`, `project_id`) 22 | ); 23 | 24 | -------------------------------------------------------------------------------- /pkg/db/schema/devops/V0_2__credential.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `project_credential` ( 2 | `project_id` VARCHAR(50) NOT NULL, 3 | `credential_id` VARCHAR(255) NOT NULL, 4 | `domain` VARCHAR(255) NOT NULL, 5 | `creator` VARCHAR(50) NOT NULL, 6 | `create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, 7 | PRIMARY KEY (`project_id`, `credential_id`, `domain`) 8 | ); 9 | -------------------------------------------------------------------------------- /pkg/db/scripts/ddl_init.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cd /flyway/sql/ddl 4 | 5 | [ -n "$PASSWORD" ] && OPT="-p$(echo "$PASSWORD" | tr -d '\n')" 6 | 7 | for F in $(ls *.sql) 8 | do 9 | echo "Start process $F" 10 | mysql "$@" "$OPT" < "$F" 11 | if [ $? -ne 0 ]; then 12 | echo "Process $F failed" 13 | return 1 14 | else 15 | echo "Process $F successful" 16 | fi 17 | done 18 | -------------------------------------------------------------------------------- /pkg/gojenkins/README.md: -------------------------------------------------------------------------------- 1 | # Jenkins API Client for Go 2 | 3 | 4 | ## About 5 | 6 | Jenkins is the most popular Open Source Continuous Integration system. This Library will help you interact with Jenkins in a more developer-friendly way. 7 | 8 | Fork From https://github.com/bndr/gojenkins 9 | 10 | These are some of the features that are currently implemented: 11 | 12 | * Get information on test-results of completed/failed build 13 | * Ability to query Nodes, and manipulate them. Start, Stop, set Offline. 14 | * Ability to query Jobs, and manipulate them. 15 | * Get Plugins, Builds, Artifacts, Fingerprints 16 | * Validate Fingerprints of Artifacts 17 | * Get Current Queue, Cancel Tasks 18 | * etc. For all methods go to GoDoc Reference. 19 | 20 | Add some features: 21 | 22 | * Credentials Management 23 | * Pipeline Model Converter 24 | * RBAC control 25 | -------------------------------------------------------------------------------- /pkg/gojenkins/_tests/build_history.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
-------------------------------------------------------------------------------- /pkg/gojenkins/_tests/job.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Some Job Description 5 | false 6 | 7 | 8 | 9 | 10 | params1 11 | description 12 | defaultVal 13 | 14 | 15 | 16 | 17 | 18 | true 19 | false 20 | false 21 | false 22 | 23 | false 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /pkg/gojenkins/constants.go: -------------------------------------------------------------------------------- 1 | package gojenkins 2 | 3 | const ( 4 | STATUS_FAIL = "FAIL" 5 | STATUS_ERROR = "ERROR" 6 | STATUS_ABORTED = "ABORTED" 7 | STATUS_REGRESSION = "REGRESSION" 8 | STATUS_SUCCESS = "SUCCESS" 9 | STATUS_FIXED = "FIXED" 10 | STATUS_PASSED = "PASSED" 11 | RESULT_STATUS_FAILURE = "FAILURE" 12 | RESULT_STATUS_FAILED = "FAILED" 13 | RESULT_STATUS_SKIPPED = "SKIPPED" 14 | STR_RE_SPLIT_VIEW = "(.*)/view/([^/]*)/?" 15 | ) 16 | 17 | const ( 18 | GLOBAL_ROLE = "globalRoles" 19 | PROJECT_ROLE = "projectRoles" 20 | ) 21 | -------------------------------------------------------------------------------- /pkg/gojenkins/executor.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Vadim Kravcenko 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 | // not use this file except in compliance with the License. You may obtain 5 | // a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | package gojenkins 16 | 17 | type Executor struct { 18 | Raw *ExecutorResponse 19 | Jenkins *Jenkins 20 | } 21 | type ViewData struct { 22 | Name string `json:"name"` 23 | URL string `json:"url"` 24 | } 25 | type ExecutorResponse struct { 26 | AssignedLabels []struct{} `json:"assignedLabels"` 27 | Description interface{} `json:"description"` 28 | Jobs []InnerJob `json:"jobs"` 29 | Mode string `json:"mode"` 30 | NodeDescription string `json:"nodeDescription"` 31 | NodeName string `json:"nodeName"` 32 | NumExecutors int64 `json:"numExecutors"` 33 | OverallLoad struct{} `json:"overallLoad"` 34 | PrimaryView struct { 35 | Name string `json:"name"` 36 | URL string `json:"url"` 37 | } `json:"primaryView"` 38 | QuietingDown bool `json:"quietingDown"` 39 | SlaveAgentPort int64 `json:"slaveAgentPort"` 40 | UnlabeledLoad struct{} `json:"unlabeledLoad"` 41 | UseCrumbs bool `json:"useCrumbs"` 42 | UseSecurity bool `json:"useSecurity"` 43 | Views []ViewData `json:"views"` 44 | } 45 | -------------------------------------------------------------------------------- /pkg/gojenkins/fingerprint.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Vadim Kravcenko 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 | // not use this file except in compliance with the License. You may obtain 5 | // a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | package gojenkins 16 | 17 | import ( 18 | "errors" 19 | "fmt" 20 | ) 21 | 22 | type FingerPrint struct { 23 | Jenkins *Jenkins 24 | Base string 25 | Id string 26 | Raw *FingerPrintResponse 27 | } 28 | 29 | type FingerPrintResponse struct { 30 | FileName string `json:"fileName"` 31 | Hash string `json:"hash"` 32 | Original struct { 33 | Name string 34 | Number int64 35 | } `json:"original"` 36 | Timestamp int64 `json:"timestamp"` 37 | Usage []struct { 38 | Name string `json:"name"` 39 | Ranges struct { 40 | Ranges []struct { 41 | End int64 `json:"end"` 42 | Start int64 `json:"start"` 43 | } `json:"ranges"` 44 | } `json:"ranges"` 45 | } `json:"usage"` 46 | } 47 | 48 | func (f FingerPrint) Valid() (bool, error) { 49 | status, err := f.Poll() 50 | 51 | if err != nil { 52 | return false, err 53 | } 54 | 55 | if status != 200 || f.Raw.Hash != f.Id { 56 | return false, fmt.Errorf("Jenkins says %s is Invalid or the Status is unknown", f.Id) 57 | } 58 | return true, nil 59 | } 60 | 61 | func (f FingerPrint) ValidateForBuild(filename string, build *Build) (bool, error) { 62 | valid, err := f.Valid() 63 | if err != nil { 64 | return false, err 65 | } 66 | 67 | if valid { 68 | return true, nil 69 | } 70 | 71 | if f.Raw.FileName != filename { 72 | return false, errors.New("Filename does not Match") 73 | } 74 | if build != nil && f.Raw.Original.Name == build.Job.GetName() && 75 | f.Raw.Original.Number == build.GetBuildNumber() { 76 | return true, nil 77 | } 78 | return false, nil 79 | } 80 | 81 | func (f FingerPrint) GetInfo() (*FingerPrintResponse, error) { 82 | _, err := f.Poll() 83 | if err != nil { 84 | return nil, err 85 | } 86 | return f.Raw, nil 87 | } 88 | 89 | func (f FingerPrint) Poll() (int, error) { 90 | response, err := f.Jenkins.Requester.GetJSON(f.Base+f.Id, f.Raw, nil) 91 | if err != nil { 92 | return 0, err 93 | } 94 | return response.StatusCode, nil 95 | } 96 | -------------------------------------------------------------------------------- /pkg/gojenkins/folder.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Vadim Kravcenko 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 | // not use this file except in compliance with the License. You may obtain 5 | // a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | package gojenkins 16 | 17 | import ( 18 | "errors" 19 | "strconv" 20 | "strings" 21 | ) 22 | 23 | type Folder struct { 24 | Raw *FolderResponse 25 | Jenkins *Jenkins 26 | Base string 27 | } 28 | 29 | type FolderResponse struct { 30 | Actions []GeneralObj 31 | Description string `json:"description"` 32 | DisplayName string `json:"displayName"` 33 | Name string `json:"name"` 34 | URL string `json:"url"` 35 | Jobs []InnerJob `json:"jobs"` 36 | PrimaryView *ViewData `json:"primaryView"` 37 | Views []ViewData `json:"views"` 38 | } 39 | 40 | func (f *Folder) parentBase() string { 41 | return f.Base[:strings.LastIndex(f.Base, "/job")] 42 | } 43 | 44 | func (f *Folder) GetName() string { 45 | return f.Raw.Name 46 | } 47 | 48 | func (f *Folder) Create(name, description string) (*Folder, error) { 49 | mode := "com.cloudbees.hudson.plugins.folder.Folder" 50 | data := map[string]string{ 51 | "name": name, 52 | "mode": mode, 53 | "Submit": "OK", 54 | "json": makeJson(map[string]string{ 55 | "name": name, 56 | "mode": mode, 57 | "description": description, 58 | }), 59 | } 60 | r, err := f.Jenkins.Requester.Post(f.parentBase()+"/createItem", nil, f.Raw, data) 61 | if err != nil { 62 | return nil, err 63 | } 64 | if r.StatusCode == 200 { 65 | f.Poll() 66 | return f, nil 67 | } 68 | return nil, errors.New(strconv.Itoa(r.StatusCode)) 69 | } 70 | 71 | func (f *Folder) Poll() (int, error) { 72 | response, err := f.Jenkins.Requester.GetJSON(f.Base, f.Raw, nil) 73 | if err != nil { 74 | return 0, err 75 | } 76 | return response.StatusCode, nil 77 | } 78 | -------------------------------------------------------------------------------- /pkg/gojenkins/label.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Vadim Kravcenko 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 | // not use this file except in compliance with the License. You may obtain 5 | // a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | package gojenkins 16 | 17 | type Label struct { 18 | Raw *LabelResponse 19 | Jenkins *Jenkins 20 | Base string 21 | } 22 | 23 | type MODE string 24 | 25 | const ( 26 | NORMAL MODE = "NORMAL" 27 | EXCLUSIVE = "EXCLUSIVE" 28 | ) 29 | 30 | type LabelNode struct { 31 | NodeName string `json:"nodeName"` 32 | NodeDescription string `json:"nodeDescription"` 33 | NumExecutors int64 `json:"numExecutors"` 34 | Mode string `json:"mode"` 35 | Class string `json:"_class"` 36 | } 37 | 38 | type LabelResponse struct { 39 | Name string `json:"name"` 40 | Description string `json:"description"` 41 | Nodes []LabelNode `json:"nodes"` 42 | Offline bool `json:"offline"` 43 | IdleExecutors int64 `json:"idleExecutors"` 44 | BusyExecutors int64 `json:"busyExecutors"` 45 | TotalExecutors int64 `json:"totalExecutors"` 46 | } 47 | 48 | func (l *Label) GetName() string { 49 | return l.Raw.Name 50 | } 51 | 52 | func (l *Label) GetNodes() []LabelNode { 53 | return l.Raw.Nodes 54 | } 55 | 56 | func (l *Label) Poll() (int, error) { 57 | response, err := l.Jenkins.Requester.GetJSON(l.Base, l.Raw, nil) 58 | if err != nil { 59 | return 0, err 60 | } 61 | return response.StatusCode, nil 62 | } 63 | -------------------------------------------------------------------------------- /pkg/gojenkins/plugin.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Vadim Kravcenko 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 | // not use this file except in compliance with the License. You may obtain 5 | // a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | package gojenkins 16 | 17 | import ( 18 | "strconv" 19 | ) 20 | 21 | type Plugins struct { 22 | Jenkins *Jenkins 23 | Raw *PluginResponse 24 | Base string 25 | Depth int 26 | } 27 | 28 | type PluginResponse struct { 29 | Plugins []Plugin `json:"plugins"` 30 | } 31 | 32 | type Plugin struct { 33 | Active bool `json:"active"` 34 | BackupVersion interface{} `json:"backupVersion"` 35 | Bundled bool `json:"bundled"` 36 | Deleted bool `json:"deleted"` 37 | Dependencies []struct { 38 | Optional string `json:"optional"` 39 | ShortName string `json:"shortname"` 40 | Version string `json:"version"` 41 | } `json:"dependencies"` 42 | Downgradable bool `json:"downgradable"` 43 | Enabled bool `json:"enabled"` 44 | HasUpdate bool `json:"hasUpdate"` 45 | LongName string `json:"longName"` 46 | Pinned bool `json:"pinned"` 47 | ShortName string `json:"shortName"` 48 | SupportsDynamicLoad string `json:"supportsDynamicLoad"` 49 | URL string `json:"url"` 50 | Version string `json:"version"` 51 | } 52 | 53 | func (p *Plugins) Count() int { 54 | return len(p.Raw.Plugins) 55 | } 56 | 57 | func (p *Plugins) Contains(name string) *Plugin { 58 | for _, p := range p.Raw.Plugins { 59 | if p.LongName == name || p.ShortName == name { 60 | return &p 61 | } 62 | } 63 | return nil 64 | } 65 | 66 | func (p *Plugins) Poll() (int, error) { 67 | qr := map[string]string{ 68 | "depth": strconv.Itoa(p.Depth), 69 | } 70 | response, err := p.Jenkins.Requester.GetJSON(p.Base, p.Raw, qr) 71 | if err != nil { 72 | return 0, err 73 | } 74 | return response.StatusCode, nil 75 | } 76 | -------------------------------------------------------------------------------- /pkg/gojenkins/utils.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Vadim Kravcenko 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 | // not use this file except in compliance with the License. You may obtain 5 | // a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | package gojenkins 16 | 17 | import ( 18 | "encoding/json" 19 | "strings" 20 | "time" 21 | "unicode/utf8" 22 | ) 23 | 24 | func makeJson(data interface{}) string { 25 | str, err := json.Marshal(data) 26 | if err != nil { 27 | return "" 28 | } 29 | return string(json.RawMessage(str)) 30 | } 31 | 32 | func Reverse(s string) string { 33 | size := len(s) 34 | buf := make([]byte, size) 35 | for start := 0; start < size; { 36 | r, n := utf8.DecodeRuneInString(s[start:]) 37 | start += n 38 | utf8.EncodeRune(buf[size-start:], r) 39 | } 40 | return string(buf) 41 | } 42 | 43 | type JenkinsBlueTime time.Time 44 | 45 | func (t *JenkinsBlueTime) UnmarshalJSON(b []byte) error { 46 | if b == nil || strings.Trim(string(b), "\"") == "null" { 47 | *t = JenkinsBlueTime(time.Time{}) 48 | return nil 49 | } 50 | j, err := time.Parse("2006-01-02T15:04:05.000-0700", strings.Trim(string(b), "\"")) 51 | 52 | if err != nil { 53 | return err 54 | } 55 | *t = JenkinsBlueTime(j) 56 | return nil 57 | } 58 | 59 | func (t JenkinsBlueTime) MarshalJSON() ([]byte, error) { 60 | return json.Marshal(time.Time(t)) 61 | } 62 | -------------------------------------------------------------------------------- /pkg/logger/logger_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The KubeSphere Authors. 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | 14 | package logger 15 | 16 | import ( 17 | "bytes" 18 | "testing" 19 | 20 | "github.com/stretchr/testify/assert" 21 | ) 22 | 23 | func readBuf(buf *bytes.Buffer) string { 24 | str := buf.String() 25 | buf.Reset() 26 | return str 27 | } 28 | 29 | func TestLogger(t *testing.T) { 30 | buf := new(bytes.Buffer) 31 | SetOutput(buf) 32 | 33 | Debug("debug log, should ignore by default") 34 | assert.Empty(t, readBuf(buf)) 35 | 36 | Info("info log, should visable") 37 | assert.Contains(t, readBuf(buf), "info log, should visable") 38 | 39 | Info("format [%d]", 111) 40 | log := readBuf(buf) 41 | assert.Contains(t, log, "format [111]") 42 | t.Log(log) 43 | 44 | SetLevelByString("debug") 45 | Debug("debug log, now it becomes visible") 46 | assert.Contains(t, readBuf(buf), "debug log, now it becomes visible") 47 | 48 | logger = NewLogger() 49 | logger.SetPrefix("(prefix)").SetSuffix("(suffix)").SetOutput(buf) 50 | 51 | logger.Warn("log_content") 52 | log = readBuf(buf) 53 | assert.Regexp(t, " -WARNING- \\(prefix\\)log_content \\(logger_test.go:\\d+\\)\\(suffix\\)", log) 54 | t.Log(log) 55 | 56 | logger.HideCallstack() 57 | logger.Warn("log_content") 58 | log = readBuf(buf) 59 | assert.Regexp(t, " -WARNING- \\(prefix\\)log_content\\(suffix\\)", log) 60 | t.Log(log) 61 | } 62 | -------------------------------------------------------------------------------- /pkg/models/common.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The KubeSphere Authors. 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | 14 | package models 15 | 16 | import ( 17 | "github.com/fatih/structs" 18 | 19 | "kubesphere.io/devops/pkg/utils/stringutils" 20 | ) 21 | 22 | func GetColumnsFromStruct(s interface{}) []string { 23 | names := structs.Names(s) 24 | for i, name := range names { 25 | names[i] = stringutils.CamelCaseToUnderscore(name) 26 | } 27 | return names 28 | } 29 | 30 | func GetColumnsFromStructWithPrefix(prefix string, s interface{}) []string { 31 | names := structs.Names(s) 32 | for i, name := range names { 33 | names[i] = WithPrefix(prefix, stringutils.CamelCaseToUnderscore(name)) 34 | } 35 | return names 36 | } 37 | 38 | func WithPrefix(prefix, str string) string { 39 | return prefix + "." + str 40 | } 41 | -------------------------------------------------------------------------------- /pkg/models/credential.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | "time" 5 | 6 | "github.com/asaskevich/govalidator" 7 | ) 8 | 9 | const ( 10 | ProjectCredentialTableName = "project_credential" 11 | ProjectCredentialIdColumn = "credential_id" 12 | ProjectCredentialDomainColumn = "domain" 13 | ) 14 | 15 | type ProjectCredential struct { 16 | ProjectId string `json:"project_id"` 17 | CredentialId string `json:"credential_id"` 18 | Domain string `json:"domain"` 19 | Creator string `json:"creator"` 20 | CreateTime time.Time `json:"create_time"` 21 | } 22 | 23 | var ProjectCredentialColumns = GetColumnsFromStruct(&ProjectCredential{}) 24 | 25 | func NewProjectCredential(projectId, credentialId, domain, creator string) *ProjectCredential { 26 | if govalidator.IsNull(domain) { 27 | domain = "_" 28 | } 29 | return &ProjectCredential{ 30 | ProjectId: projectId, 31 | CredentialId: credentialId, 32 | Domain: domain, 33 | Creator: creator, 34 | CreateTime: time.Now(), 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /pkg/models/membership.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The KubeSphere Authors. 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | 14 | package models 15 | 16 | import "kubesphere.io/devops/pkg/constants" 17 | 18 | const ( 19 | ProjectMembershipTableName = "project_membership" 20 | ProjectMembershipUsernameColumn = "username" 21 | ProjectMembershipProjectIdColumn = "project_id" 22 | ProjectMembershipRoleColumn = "role" 23 | ) 24 | 25 | type ProjectMembership struct { 26 | Username string `json:"username"` 27 | ProjectId string `json:"project_id" db:"project_id"` 28 | Role string `json:"role"` 29 | Status string `json:"status"` 30 | GrantBy string `json:"grand_by,omitempty"` 31 | } 32 | 33 | var ProjectMembershipColumns = GetColumnsFromStruct(&ProjectMembership{}) 34 | 35 | func NewProjectMemberShip(username, projectId, role, grantBy string) *ProjectMembership { 36 | return &ProjectMembership{ 37 | Username: username, 38 | ProjectId: projectId, 39 | Role: role, 40 | Status: constants.StatusActive, 41 | GrantBy: grantBy, 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /pkg/models/project.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The KubeSphere Authors. 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | 14 | package models 15 | 16 | import ( 17 | "time" 18 | 19 | "kubesphere.io/devops/pkg/constants" 20 | "kubesphere.io/devops/pkg/utils/idutils" 21 | ) 22 | 23 | var ProjectColumns = GetColumnsFromStruct(&Project{}) 24 | 25 | const ( 26 | ProjectTableName = "project" 27 | ProjectPrefix = "project-" 28 | ProjectDescriptionColumn = "description" 29 | ProjectIdColumn = "project_id" 30 | ProjectExtraColumn = "extra" 31 | ) 32 | 33 | type Project struct { 34 | ProjectId string `json:"project_id" db:"project_id"` 35 | Name string `json:"name"` 36 | Description string `json:"description"` 37 | Creator string `json:"creator"` 38 | CreateTime time.Time `json:"create_time"` 39 | Status string `json:"status"` 40 | Visibility string `json:"visibility"` 41 | Extra string `json:"extra"` 42 | } 43 | 44 | func NewProject(name, description, creator, extra string) *Project { 45 | return &Project{ 46 | ProjectId: idutils.GetUuid(ProjectPrefix), 47 | Name: name, 48 | Description: description, 49 | Creator: creator, 50 | CreateTime: time.Now(), 51 | Status: constants.StatusActive, 52 | Visibility: constants.VisibilityPrivate, 53 | Extra: extra, 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /pkg/server/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The KubeSphere Authors. 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | 14 | package main 15 | 16 | import ( 17 | "kubesphere.io/devops/pkg/config" 18 | "kubesphere.io/devops/pkg/service" 19 | ) 20 | 21 | func main() { 22 | cfg := config.LoadConf() 23 | service.Serve(cfg) 24 | } 25 | -------------------------------------------------------------------------------- /pkg/service/router.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The KubeSphere Authors. 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | 14 | package service 15 | 16 | import ( 17 | "github.com/ant0ine/go-json-rest/rest" 18 | 19 | "kubesphere.io/devops/pkg/logger" 20 | ) 21 | 22 | func Router(s *Server) (app rest.App) { 23 | 24 | app, err := rest.MakeRouter( 25 | rest.Get("/projects", s.Projects.GetProjectsHandler), 26 | rest.Get("/projects/:id", s.Projects.GetProjectHandler), 27 | rest.Post("/projects", s.Projects.CreateProjectHandler), 28 | rest.Patch("/projects/:id", s.Projects.UpdateProjectHandler), 29 | rest.Delete("/projects/:id", s.Projects.DeleteProjectHandler), 30 | rest.Get("/projects/:id/members", s.Projects.GetMembersHandler), 31 | rest.Get("/projects/:id/members/:uid", s.Projects.GetMemberHandler), 32 | rest.Post("/projects/:id/members", s.Projects.AddProjectMemberHandler), 33 | rest.Patch("/projects/:id/members/:uid", s.Projects.UpdateMemberHandler), 34 | rest.Delete("/projects/:id/members/:uid", s.Projects.DeleteMemberHandler), 35 | rest.Post("/projects/:id/credentials", s.Projects.CreateCredentialHandler), 36 | rest.Delete("/projects/:id/credentials/:cid", s.Projects.DeleteCredentialHandler), 37 | rest.Put("/projects/:id/credentials/:cid", s.Projects.UpdateCredentialHandler), 38 | rest.Get("/projects/:id/credentials/:cid", s.Projects.GetCredentialHandler), 39 | rest.Get("/projects/:id/credentials", s.Projects.GetCredentialsHandler), 40 | rest.Get("/projects/:id/pipelines/:pid/config", s.Projects.GetPipelineHandler), 41 | rest.Post("/projects/:id/pipelines", s.Projects.CreatePipelineHandler), 42 | rest.Put("/projects/:id/pipelines/:pid", s.Projects.UpdatePipelineHandler), 43 | rest.Delete("/projects/:id/pipelines/:pid", s.Projects.DeletePipelineHandler), 44 | rest.Get("/projects/:id/pipelines/:pid/scm", s.Projects.GetPipelineScmHandler), 45 | rest.Get("/projects/default_roles/", s.Projects.GetProjectDefaultRolesHandler), 46 | rest.Get("/projects/:id/pipelines/:pid/sonarStatus", s.Projects.GetPipelineSonarHandler), 47 | rest.Get("/projects/:id/pipelines/:pid/branches/:bid/sonarStatus", s.Projects.GetMultiBranchPipelineSonarHandler)) 48 | 49 | if err != nil { 50 | logger.Critical("%+v", err) 51 | return 52 | } 53 | return 54 | } 55 | -------------------------------------------------------------------------------- /pkg/service/server.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The KubeSphere Authors. 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | 14 | package service 15 | 16 | import ( 17 | "net/http" 18 | "time" 19 | 20 | "github.com/ant0ine/go-json-rest/rest" 21 | 22 | "kubesphere.io/devops/pkg/config" 23 | "kubesphere.io/devops/pkg/ds" 24 | "kubesphere.io/devops/pkg/logger" 25 | "kubesphere.io/devops/pkg/service/projects" 26 | ) 27 | 28 | type Server struct { 29 | Ds *ds.Ds 30 | Projects *projects.ProjectService 31 | } 32 | 33 | const APIVersion = "/api/v1alpha" 34 | 35 | func Serve(cfg *config.Config) { 36 | 37 | s := Server{} 38 | s.Ds = ds.NewDs(cfg) 39 | s.Projects = &projects.ProjectService{Ds: s.Ds} 40 | 41 | // func to connect jenkins solve https://issues.jenkins-ci.org/browse/JENKINS-2489 42 | go func() { 43 | for { 44 | s.Ds.Jenkins.Info() 45 | time.Sleep(time.Second * 30) 46 | } 47 | }() 48 | 49 | api := rest.NewApi() 50 | api.Use(rest.DefaultDevStack...) 51 | api.SetApp(Router(&s)) 52 | http.Handle(APIVersion+"/", http.StripPrefix(APIVersion, api.MakeHandler())) 53 | logger.Critical("%+v", http.ListenAndServe(":8080", nil)) 54 | } 55 | -------------------------------------------------------------------------------- /pkg/utils/idutils/id_utils.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The KubeSphere Authors. 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | 14 | package idutils 15 | 16 | import ( 17 | "errors" 18 | "net" 19 | "os" 20 | 21 | "github.com/golang/example/stringutil" 22 | "github.com/sony/sonyflake" 23 | hashids "github.com/speps/go-hashids" 24 | 25 | "kubesphere.io/devops/pkg/utils/stringutils" 26 | ) 27 | 28 | var sf *sonyflake.Sonyflake 29 | 30 | func init() { 31 | var st sonyflake.Settings 32 | if len(os.Getenv("DEVOPSPHERE_IP")) != 0 { 33 | st.MachineID = machineID 34 | } 35 | sf = sonyflake.NewSonyflake(st) 36 | if sf == nil { 37 | panic("failed to initialize sonyflake") 38 | } 39 | } 40 | 41 | func GetIntId() uint64 { 42 | id, err := sf.NextID() 43 | if err != nil { 44 | panic(err) 45 | } 46 | return id 47 | } 48 | 49 | // format likes: B6BZVN3mOPvx 50 | func GetUuid(prefix string) string { 51 | id := GetIntId() 52 | hd := hashids.NewData() 53 | h, err := hashids.NewWithData(hd) 54 | if err != nil { 55 | panic(err) 56 | } 57 | i, err := h.Encode([]int{int(id)}) 58 | if err != nil { 59 | panic(err) 60 | } 61 | 62 | return prefix + stringutils.Reverse(i) 63 | } 64 | 65 | const Alphabet36 = "abcdefghijklmnopqrstuvwxyz1234567890" 66 | 67 | // format likes: 300m50zn91nwz5 68 | func GetUuid36(prefix string) string { 69 | id := GetIntId() 70 | hd := hashids.NewData() 71 | hd.Alphabet = Alphabet36 72 | h, err := hashids.NewWithData(hd) 73 | if err != nil { 74 | panic(err) 75 | } 76 | i, err := h.Encode([]int{int(id)}) 77 | if err != nil { 78 | panic(err) 79 | } 80 | 81 | return prefix + stringutil.Reverse(i) 82 | } 83 | 84 | func machineID() (uint16, error) { 85 | ipStr := os.Getenv("DEVOPSPHERE_IP") 86 | if len(ipStr) == 0 { 87 | return 0, errors.New("'DEVOPSPHERE_IP' environment variable not set") 88 | } 89 | ip := net.ParseIP(ipStr) 90 | if len(ip) < 4 { 91 | return 0, errors.New("invalid IP") 92 | } 93 | return uint16(ip[2])<<8 + uint16(ip[3]), nil 94 | } 95 | -------------------------------------------------------------------------------- /pkg/utils/idutils/id_utils_test.go: -------------------------------------------------------------------------------- 1 | package idutils 2 | 3 | import ( 4 | "fmt" 5 | "sort" 6 | "testing" 7 | ) 8 | 9 | func TestGetUuid(t *testing.T) { 10 | fmt.Println(GetUuid("")) 11 | } 12 | 13 | func TestGetUuid36(t *testing.T) { 14 | fmt.Println(GetUuid36("")) 15 | } 16 | 17 | func TestGetManyUuid(t *testing.T) { 18 | var strSlice []string 19 | for i := 0; i < 10000; i++ { 20 | testId := GetUuid("") 21 | strSlice = append(strSlice, testId) 22 | } 23 | sort.Strings(strSlice) 24 | } 25 | -------------------------------------------------------------------------------- /pkg/utils/reflectutils/reflect.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The KubeSphere Authors. 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | 14 | package reflectutils 15 | 16 | import "reflect" 17 | 18 | func In(value interface{}, container interface{}) bool { 19 | containerValue := reflect.ValueOf(container) 20 | switch reflect.TypeOf(container).Kind() { 21 | case reflect.Slice, reflect.Array: 22 | for i := 0; i < containerValue.Len(); i++ { 23 | if containerValue.Index(i).Interface() == value { 24 | return true 25 | } 26 | } 27 | case reflect.Map: 28 | if containerValue.MapIndex(reflect.ValueOf(value)).IsValid() { 29 | return true 30 | } 31 | default: 32 | return false 33 | } 34 | return false 35 | } 36 | -------------------------------------------------------------------------------- /pkg/utils/stringutils/string.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The KubeSphere Authors. 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | 14 | package stringutils 15 | 16 | import ( 17 | "net/http" 18 | "strconv" 19 | "unicode/utf8" 20 | 21 | "github.com/asaskevich/govalidator" 22 | "kubesphere.io/devops/pkg/gojenkins" 23 | ) 24 | 25 | // Creates an slice of slice values not included in the other given slice. 26 | func Diff(base, exclude []string) (result []string) { 27 | excludeMap := make(map[string]bool) 28 | for _, s := range exclude { 29 | excludeMap[s] = true 30 | } 31 | for _, s := range base { 32 | if !excludeMap[s] { 33 | result = append(result, s) 34 | } 35 | } 36 | return result 37 | } 38 | 39 | func Unique(ss []string) (result []string) { 40 | smap := make(map[string]bool) 41 | for _, s := range ss { 42 | smap[s] = true 43 | } 44 | for s := range smap { 45 | result = append(result, s) 46 | } 47 | return result 48 | } 49 | 50 | func CamelCaseToUnderscore(str string) string { 51 | return govalidator.CamelCaseToUnderscore(str) 52 | } 53 | 54 | func UnderscoreToCamelCase(str string) string { 55 | return govalidator.UnderscoreToCamelCase(str) 56 | } 57 | 58 | func FindString(array []string, str string) int { 59 | for index, s := range array { 60 | if str == s { 61 | return index 62 | } 63 | } 64 | return -1 65 | } 66 | 67 | func StringIn(str string, array []string) bool { 68 | return FindString(array, str) > -1 69 | } 70 | 71 | func Reverse(s string) string { 72 | size := len(s) 73 | buf := make([]byte, size) 74 | for start := 0; start < size; { 75 | r, n := utf8.DecodeRuneInString(s[start:]) 76 | start += n 77 | utf8.EncodeRune(buf[size-start:], r) 78 | } 79 | return string(buf) 80 | } 81 | 82 | func GetJenkinsStatusCode(jenkinsErr error) int { 83 | if code, err := strconv.Atoi(jenkinsErr.Error()); err == nil { 84 | message := http.StatusText(code) 85 | if !govalidator.IsNull(message) { 86 | return code 87 | } 88 | } 89 | if jErr, ok := jenkinsErr.(*gojenkins.ErrorResponse); ok { 90 | return jErr.Response.StatusCode 91 | } 92 | return http.StatusInternalServerError 93 | } 94 | -------------------------------------------------------------------------------- /pkg/utils/userutils/user.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The KubeSphere Authors. 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | 14 | package userutils 15 | 16 | import "github.com/ant0ine/go-json-rest/rest" 17 | 18 | func GetUserNameFromRequest(request *rest.Request) string { 19 | return request.Header.Get("X-Token-Username") 20 | } 21 | -------------------------------------------------------------------------------- /sonar-project.properties: -------------------------------------------------------------------------------- 1 | # Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. 2 | # This property is optional if sonar.modules is set. 3 | sonar.sources=. 4 | sonar.tests=. 5 | sonar.test.inclusions=pkg/*_test.go 6 | sonar.test.exclusions=**/vendor/**,**/run/** 7 | sonar.exclusions=**/*_test.go,**/vendor/**,**/run/** 8 | sonar.go.coverage.reportPaths=test_coverage.out 9 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/.gitignore: -------------------------------------------------------------------------------- 1 | TAGS 2 | tags 3 | .*.swp 4 | tomlcheck/tomlcheck 5 | toml.test 6 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go: 3 | - 1.1 4 | - 1.2 5 | - 1.3 6 | - 1.4 7 | - 1.5 8 | - 1.6 9 | - tip 10 | install: 11 | - go install ./... 12 | - go get github.com/BurntSushi/toml-test 13 | script: 14 | - export PATH="$PATH:$HOME/gopath/bin" 15 | - make test 16 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/COMPATIBLE: -------------------------------------------------------------------------------- 1 | Compatible with TOML version 2 | [v0.4.0](https://github.com/toml-lang/toml/blob/v0.4.0/versions/en/toml-v0.4.0.md) 3 | 4 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/COPYING: -------------------------------------------------------------------------------- 1 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 2 | Version 2, December 2004 3 | 4 | Copyright (C) 2004 Sam Hocevar 5 | 6 | Everyone is permitted to copy and distribute verbatim or modified 7 | copies of this license document, and changing it is allowed as long 8 | as the name is changed. 9 | 10 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 11 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 12 | 13 | 0. You just DO WHAT THE FUCK YOU WANT TO. 14 | 15 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/Makefile: -------------------------------------------------------------------------------- 1 | install: 2 | go install ./... 3 | 4 | test: install 5 | go test -v 6 | toml-test toml-test-decoder 7 | toml-test -encoder toml-test-encoder 8 | 9 | fmt: 10 | gofmt -w *.go */*.go 11 | colcheck *.go */*.go 12 | 13 | tags: 14 | find ./ -name '*.go' -print0 | xargs -0 gotags > TAGS 15 | 16 | push: 17 | git push origin master 18 | git push github master 19 | 20 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/cmd/toml-test-decoder/COPYING: -------------------------------------------------------------------------------- 1 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 2 | Version 2, December 2004 3 | 4 | Copyright (C) 2004 Sam Hocevar 5 | 6 | Everyone is permitted to copy and distribute verbatim or modified 7 | copies of this license document, and changing it is allowed as long 8 | as the name is changed. 9 | 10 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 11 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 12 | 13 | 0. You just DO WHAT THE FUCK YOU WANT TO. 14 | 15 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/cmd/toml-test-encoder/COPYING: -------------------------------------------------------------------------------- 1 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 2 | Version 2, December 2004 3 | 4 | Copyright (C) 2004 Sam Hocevar 5 | 6 | Everyone is permitted to copy and distribute verbatim or modified 7 | copies of this license document, and changing it is allowed as long 8 | as the name is changed. 9 | 10 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 11 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 12 | 13 | 0. You just DO WHAT THE FUCK YOU WANT TO. 14 | 15 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/cmd/tomlv/COPYING: -------------------------------------------------------------------------------- 1 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 2 | Version 2, December 2004 3 | 4 | Copyright (C) 2004 Sam Hocevar 5 | 6 | Everyone is permitted to copy and distribute verbatim or modified 7 | copies of this license document, and changing it is allowed as long 8 | as the name is changed. 9 | 10 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 11 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 12 | 13 | 0. You just DO WHAT THE FUCK YOU WANT TO. 14 | 15 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Package toml provides facilities for decoding and encoding TOML configuration 3 | files via reflection. There is also support for delaying decoding with 4 | the Primitive type, and querying the set of keys in a TOML document with the 5 | MetaData type. 6 | 7 | The specification implemented: https://github.com/toml-lang/toml 8 | 9 | The sub-command github.com/BurntSushi/toml/cmd/tomlv can be used to verify 10 | whether a file is a valid TOML document. It can also be used to print the 11 | type of each key in a TOML document. 12 | 13 | Testing 14 | 15 | There are two important types of tests used for this package. The first is 16 | contained inside '*_test.go' files and uses the standard Go unit testing 17 | framework. These tests are primarily devoted to holistically testing the 18 | decoder and encoder. 19 | 20 | The second type of testing is used to verify the implementation's adherence 21 | to the TOML specification. These tests have been factored into their own 22 | project: https://github.com/BurntSushi/toml-test 23 | 24 | The reason the tests are in a separate project is so that they can be used by 25 | any implementation of TOML. Namely, it is language agnostic. 26 | */ 27 | package toml 28 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/encoding_types.go: -------------------------------------------------------------------------------- 1 | // +build go1.2 2 | 3 | package toml 4 | 5 | // In order to support Go 1.1, we define our own TextMarshaler and 6 | // TextUnmarshaler types. For Go 1.2+, we just alias them with the 7 | // standard library interfaces. 8 | 9 | import ( 10 | "encoding" 11 | ) 12 | 13 | // TextMarshaler is a synonym for encoding.TextMarshaler. It is defined here 14 | // so that Go 1.1 can be supported. 15 | type TextMarshaler encoding.TextMarshaler 16 | 17 | // TextUnmarshaler is a synonym for encoding.TextUnmarshaler. It is defined 18 | // here so that Go 1.1 can be supported. 19 | type TextUnmarshaler encoding.TextUnmarshaler 20 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/encoding_types_1.1.go: -------------------------------------------------------------------------------- 1 | // +build !go1.2 2 | 3 | package toml 4 | 5 | // These interfaces were introduced in Go 1.2, so we add them manually when 6 | // compiling for Go 1.1. 7 | 8 | // TextMarshaler is a synonym for encoding.TextMarshaler. It is defined here 9 | // so that Go 1.1 can be supported. 10 | type TextMarshaler interface { 11 | MarshalText() (text []byte, err error) 12 | } 13 | 14 | // TextUnmarshaler is a synonym for encoding.TextUnmarshaler. It is defined 15 | // here so that Go 1.1 can be supported. 16 | type TextUnmarshaler interface { 17 | UnmarshalText(text []byte) error 18 | } 19 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/session.vim: -------------------------------------------------------------------------------- 1 | au BufWritePost *.go silent!make tags > /dev/null 2>&1 2 | -------------------------------------------------------------------------------- /vendor/github.com/PuerkitoBio/goquery/.gitattributes: -------------------------------------------------------------------------------- 1 | testdata/* linguist-vendored 2 | -------------------------------------------------------------------------------- /vendor/github.com/PuerkitoBio/goquery/.gitignore: -------------------------------------------------------------------------------- 1 | # editor temporary files 2 | *.sublime-* 3 | .DS_Store 4 | *.swp 5 | #*.*# 6 | tags 7 | 8 | # direnv config 9 | .env* 10 | 11 | # test binaries 12 | *.test 13 | 14 | # coverage and profilte outputs 15 | *.out 16 | 17 | -------------------------------------------------------------------------------- /vendor/github.com/PuerkitoBio/goquery/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.1 5 | - 1.2.x 6 | - 1.3.x 7 | - 1.4.x 8 | - 1.5.x 9 | - 1.6.x 10 | - 1.7.x 11 | - 1.8.x 12 | - 1.9.x 13 | - "1.10.x" 14 | - 1.11.x 15 | - tip 16 | 17 | -------------------------------------------------------------------------------- /vendor/github.com/PuerkitoBio/goquery/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012-2016, Martin Angers & Contributors 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | 8 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | 10 | * Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 13 | -------------------------------------------------------------------------------- /vendor/github.com/PuerkitoBio/goquery/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/PuerkitoBio/goquery 2 | 3 | require ( 4 | github.com/andybalholm/cascadia v1.0.0 5 | golang.org/x/net v0.0.0-20181114220301-adae6a3d119a 6 | ) 7 | -------------------------------------------------------------------------------- /vendor/github.com/PuerkitoBio/goquery/go.sum: -------------------------------------------------------------------------------- 1 | github.com/andybalholm/cascadia v1.0.0 h1:hOCXnnZ5A+3eVDX8pvgl4kofXv2ELss0bKcqRySc45o= 2 | github.com/andybalholm/cascadia v1.0.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y= 3 | golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 4 | golang.org/x/net v0.0.0-20181114220301-adae6a3d119a h1:gOpx8G595UYyvj8UK4+OFyY4rx037g3fmfhe5SasG3U= 5 | golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 6 | -------------------------------------------------------------------------------- /vendor/github.com/PuerkitoBio/goquery/iteration.go: -------------------------------------------------------------------------------- 1 | package goquery 2 | 3 | // Each iterates over a Selection object, executing a function for each 4 | // matched element. It returns the current Selection object. The function 5 | // f is called for each element in the selection with the index of the 6 | // element in that selection starting at 0, and a *Selection that contains 7 | // only that element. 8 | func (s *Selection) Each(f func(int, *Selection)) *Selection { 9 | for i, n := range s.Nodes { 10 | f(i, newSingleSelection(n, s.document)) 11 | } 12 | return s 13 | } 14 | 15 | // EachWithBreak iterates over a Selection object, executing a function for each 16 | // matched element. It is identical to Each except that it is possible to break 17 | // out of the loop by returning false in the callback function. It returns the 18 | // current Selection object. 19 | func (s *Selection) EachWithBreak(f func(int, *Selection) bool) *Selection { 20 | for i, n := range s.Nodes { 21 | if !f(i, newSingleSelection(n, s.document)) { 22 | return s 23 | } 24 | } 25 | return s 26 | } 27 | 28 | // Map passes each element in the current matched set through a function, 29 | // producing a slice of string holding the returned values. The function 30 | // f is called for each element in the selection with the index of the 31 | // element in that selection starting at 0, and a *Selection that contains 32 | // only that element. 33 | func (s *Selection) Map(f func(int, *Selection) string) (result []string) { 34 | for i, n := range s.Nodes { 35 | result = append(result, f(i, newSingleSelection(n, s.document))) 36 | } 37 | 38 | return result 39 | } 40 | -------------------------------------------------------------------------------- /vendor/github.com/PuerkitoBio/goquery/query.go: -------------------------------------------------------------------------------- 1 | package goquery 2 | 3 | import "golang.org/x/net/html" 4 | 5 | // Is checks the current matched set of elements against a selector and 6 | // returns true if at least one of these elements matches. 7 | func (s *Selection) Is(selector string) bool { 8 | return s.IsMatcher(compileMatcher(selector)) 9 | } 10 | 11 | // IsMatcher checks the current matched set of elements against a matcher and 12 | // returns true if at least one of these elements matches. 13 | func (s *Selection) IsMatcher(m Matcher) bool { 14 | if len(s.Nodes) > 0 { 15 | if len(s.Nodes) == 1 { 16 | return m.Match(s.Nodes[0]) 17 | } 18 | return len(m.Filter(s.Nodes)) > 0 19 | } 20 | 21 | return false 22 | } 23 | 24 | // IsFunction checks the current matched set of elements against a predicate and 25 | // returns true if at least one of these elements matches. 26 | func (s *Selection) IsFunction(f func(int, *Selection) bool) bool { 27 | return s.FilterFunction(f).Length() > 0 28 | } 29 | 30 | // IsSelection checks the current matched set of elements against a Selection object 31 | // and returns true if at least one of these elements matches. 32 | func (s *Selection) IsSelection(sel *Selection) bool { 33 | return s.FilterSelection(sel).Length() > 0 34 | } 35 | 36 | // IsNodes checks the current matched set of elements against the specified nodes 37 | // and returns true if at least one of these elements matches. 38 | func (s *Selection) IsNodes(nodes ...*html.Node) bool { 39 | return s.FilterNodes(nodes...).Length() > 0 40 | } 41 | 42 | // Contains returns true if the specified Node is within, 43 | // at any depth, one of the nodes in the Selection object. 44 | // It is NOT inclusive, to behave like jQuery's implementation, and 45 | // unlike Javascript's .contains, so if the contained 46 | // node is itself in the selection, it returns false. 47 | func (s *Selection) Contains(n *html.Node) bool { 48 | return sliceContains(s.Nodes, n) 49 | } 50 | -------------------------------------------------------------------------------- /vendor/github.com/andybalholm/cascadia/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.3 5 | - 1.4 6 | 7 | install: 8 | - go get github.com/andybalholm/cascadia 9 | 10 | script: 11 | - go test -v 12 | 13 | notifications: 14 | email: false 15 | -------------------------------------------------------------------------------- /vendor/github.com/andybalholm/cascadia/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 Andy Balholm. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 18 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 19 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 20 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /vendor/github.com/andybalholm/cascadia/README.md: -------------------------------------------------------------------------------- 1 | # cascadia 2 | 3 | [![](https://travis-ci.org/andybalholm/cascadia.svg)](https://travis-ci.org/andybalholm/cascadia) 4 | 5 | The Cascadia package implements CSS selectors for use with the parse trees produced by the html package. 6 | 7 | To test CSS selectors without writing Go code, check out [cascadia](https://github.com/suntong/cascadia) the command line tool, a thin wrapper around this package. 8 | -------------------------------------------------------------------------------- /vendor/github.com/andybalholm/cascadia/go.mod: -------------------------------------------------------------------------------- 1 | module "github.com/andybalholm/cascadia" 2 | 3 | require "golang.org/x/net" v0.0.0-20180218175443-cbe0f9307d01 4 | -------------------------------------------------------------------------------- /vendor/github.com/ant0ine/go-json-rest/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2016 Antoine Imbert 2 | 3 | The MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /vendor/github.com/ant0ine/go-json-rest/rest/access_log_json.go: -------------------------------------------------------------------------------- 1 | package rest 2 | 3 | import ( 4 | "encoding/json" 5 | "log" 6 | "os" 7 | "time" 8 | ) 9 | 10 | // AccessLogJsonMiddleware produces the access log with records written as JSON. This middleware 11 | // depends on TimerMiddleware and RecorderMiddleware that must be in the wrapped middlewares. It 12 | // also uses request.Env["REMOTE_USER"].(string) set by the auth middlewares. 13 | type AccessLogJsonMiddleware struct { 14 | 15 | // Logger points to the logger object used by this middleware, it defaults to 16 | // log.New(os.Stderr, "", 0). 17 | Logger *log.Logger 18 | } 19 | 20 | // MiddlewareFunc makes AccessLogJsonMiddleware implement the Middleware interface. 21 | func (mw *AccessLogJsonMiddleware) MiddlewareFunc(h HandlerFunc) HandlerFunc { 22 | 23 | // set the default Logger 24 | if mw.Logger == nil { 25 | mw.Logger = log.New(os.Stderr, "", 0) 26 | } 27 | 28 | return func(w ResponseWriter, r *Request) { 29 | 30 | // call the handler 31 | h(w, r) 32 | 33 | mw.Logger.Printf("%s", makeAccessLogJsonRecord(r).asJson()) 34 | } 35 | } 36 | 37 | // AccessLogJsonRecord is the data structure used by AccessLogJsonMiddleware to create the JSON 38 | // records. (Public for documentation only, no public method uses it) 39 | type AccessLogJsonRecord struct { 40 | Timestamp *time.Time 41 | StatusCode int 42 | ResponseTime *time.Duration 43 | HttpMethod string 44 | RequestURI string 45 | RemoteUser string 46 | UserAgent string 47 | } 48 | 49 | func makeAccessLogJsonRecord(r *Request) *AccessLogJsonRecord { 50 | 51 | var timestamp *time.Time 52 | if r.Env["START_TIME"] != nil { 53 | timestamp = r.Env["START_TIME"].(*time.Time) 54 | } 55 | 56 | var statusCode int 57 | if r.Env["STATUS_CODE"] != nil { 58 | statusCode = r.Env["STATUS_CODE"].(int) 59 | } 60 | 61 | var responseTime *time.Duration 62 | if r.Env["ELAPSED_TIME"] != nil { 63 | responseTime = r.Env["ELAPSED_TIME"].(*time.Duration) 64 | } 65 | 66 | var remoteUser string 67 | if r.Env["REMOTE_USER"] != nil { 68 | remoteUser = r.Env["REMOTE_USER"].(string) 69 | } 70 | 71 | return &AccessLogJsonRecord{ 72 | Timestamp: timestamp, 73 | StatusCode: statusCode, 74 | ResponseTime: responseTime, 75 | HttpMethod: r.Method, 76 | RequestURI: r.URL.RequestURI(), 77 | RemoteUser: remoteUser, 78 | UserAgent: r.UserAgent(), 79 | } 80 | } 81 | 82 | func (r *AccessLogJsonRecord) asJson() []byte { 83 | b, err := json.Marshal(r) 84 | if err != nil { 85 | panic(err) 86 | } 87 | return b 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/ant0ine/go-json-rest/rest/api.go: -------------------------------------------------------------------------------- 1 | package rest 2 | 3 | import ( 4 | "net/http" 5 | ) 6 | 7 | // Api defines a stack of Middlewares and an App. 8 | type Api struct { 9 | stack []Middleware 10 | app App 11 | } 12 | 13 | // NewApi makes a new Api object. The Middleware stack is empty, and the App is nil. 14 | func NewApi() *Api { 15 | return &Api{ 16 | stack: []Middleware{}, 17 | app: nil, 18 | } 19 | } 20 | 21 | // Use pushes one or multiple middlewares to the stack for middlewares 22 | // maintained in the Api object. 23 | func (api *Api) Use(middlewares ...Middleware) { 24 | api.stack = append(api.stack, middlewares...) 25 | } 26 | 27 | // SetApp sets the App in the Api object. 28 | func (api *Api) SetApp(app App) { 29 | api.app = app 30 | } 31 | 32 | // MakeHandler wraps all the Middlewares of the stack and the App together, and returns an 33 | // http.Handler ready to be used. If the Middleware stack is empty the App is used directly. If the 34 | // App is nil, a HandlerFunc that does nothing is used instead. 35 | func (api *Api) MakeHandler() http.Handler { 36 | var appFunc HandlerFunc 37 | if api.app != nil { 38 | appFunc = api.app.AppFunc() 39 | } else { 40 | appFunc = func(w ResponseWriter, r *Request) {} 41 | } 42 | return http.HandlerFunc( 43 | adapterFunc( 44 | WrapMiddlewares(api.stack, appFunc), 45 | ), 46 | ) 47 | } 48 | 49 | // Defines a stack of middlewares convenient for development. Among other things: 50 | // console friendly logging, JSON indentation, error stack strace in the response. 51 | var DefaultDevStack = []Middleware{ 52 | &AccessLogApacheMiddleware{}, 53 | &TimerMiddleware{}, 54 | &RecorderMiddleware{}, 55 | &PoweredByMiddleware{}, 56 | &RecoverMiddleware{ 57 | EnableResponseStackTrace: true, 58 | }, 59 | &JsonIndentMiddleware{}, 60 | &ContentTypeCheckerMiddleware{}, 61 | } 62 | 63 | // Defines a stack of middlewares convenient for production. Among other things: 64 | // Apache CombinedLogFormat logging, gzip compression. 65 | var DefaultProdStack = []Middleware{ 66 | &AccessLogApacheMiddleware{ 67 | Format: CombinedLogFormat, 68 | }, 69 | &TimerMiddleware{}, 70 | &RecorderMiddleware{}, 71 | &PoweredByMiddleware{}, 72 | &RecoverMiddleware{}, 73 | &GzipMiddleware{}, 74 | &ContentTypeCheckerMiddleware{}, 75 | } 76 | 77 | // Defines a stack of middlewares that should be common to most of the middleware stacks. 78 | var DefaultCommonStack = []Middleware{ 79 | &TimerMiddleware{}, 80 | &RecorderMiddleware{}, 81 | &PoweredByMiddleware{}, 82 | &RecoverMiddleware{}, 83 | } 84 | -------------------------------------------------------------------------------- /vendor/github.com/ant0ine/go-json-rest/rest/content_type_checker.go: -------------------------------------------------------------------------------- 1 | package rest 2 | 3 | import ( 4 | "mime" 5 | "net/http" 6 | "strings" 7 | ) 8 | 9 | // ContentTypeCheckerMiddleware verifies the request Content-Type header and returns a 10 | // StatusUnsupportedMediaType (415) HTTP error response if it's incorrect. The expected 11 | // Content-Type is 'application/json' if the content is non-null. Note: If a charset parameter 12 | // exists, it MUST be UTF-8. 13 | type ContentTypeCheckerMiddleware struct{} 14 | 15 | // MiddlewareFunc makes ContentTypeCheckerMiddleware implement the Middleware interface. 16 | func (mw *ContentTypeCheckerMiddleware) MiddlewareFunc(handler HandlerFunc) HandlerFunc { 17 | 18 | return func(w ResponseWriter, r *Request) { 19 | 20 | mediatype, params, _ := mime.ParseMediaType(r.Header.Get("Content-Type")) 21 | charset, ok := params["charset"] 22 | if !ok { 23 | charset = "UTF-8" 24 | } 25 | 26 | // per net/http doc, means that the length is known and non-null 27 | if r.ContentLength > 0 && 28 | !(mediatype == "application/json" && strings.ToUpper(charset) == "UTF-8") { 29 | 30 | Error(w, 31 | "Bad Content-Type or charset, expected 'application/json'", 32 | http.StatusUnsupportedMediaType, 33 | ) 34 | return 35 | } 36 | 37 | // call the wrapped handler 38 | handler(w, r) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /vendor/github.com/ant0ine/go-json-rest/rest/doc.go: -------------------------------------------------------------------------------- 1 | // A quick and easy way to setup a RESTful JSON API 2 | // 3 | // http://ant0ine.github.io/go-json-rest/ 4 | // 5 | // Go-Json-Rest is a thin layer on top of net/http that helps building RESTful JSON APIs easily. 6 | // It provides fast and scalable request routing using a Trie based implementation, helpers to deal 7 | // with JSON requests and responses, and middlewares for functionalities like CORS, Auth, Gzip, 8 | // Status, ... 9 | // 10 | // Example: 11 | // 12 | // package main 13 | // 14 | // import ( 15 | // "github.com/ant0ine/go-json-rest/rest" 16 | // "log" 17 | // "net/http" 18 | // ) 19 | // 20 | // type User struct { 21 | // Id string 22 | // Name string 23 | // } 24 | // 25 | // func GetUser(w rest.ResponseWriter, req *rest.Request) { 26 | // user := User{ 27 | // Id: req.PathParam("id"), 28 | // Name: "Antoine", 29 | // } 30 | // w.WriteJson(&user) 31 | // } 32 | // 33 | // func main() { 34 | // api := rest.NewApi() 35 | // api.Use(rest.DefaultDevStack...) 36 | // router, err := rest.MakeRouter( 37 | // rest.Get("/users/:id", GetUser), 38 | // ) 39 | // if err != nil { 40 | // log.Fatal(err) 41 | // } 42 | // api.SetApp(router) 43 | // log.Fatal(http.ListenAndServe(":8080", api.MakeHandler())) 44 | // } 45 | // 46 | // 47 | package rest 48 | -------------------------------------------------------------------------------- /vendor/github.com/ant0ine/go-json-rest/rest/if.go: -------------------------------------------------------------------------------- 1 | package rest 2 | 3 | import ( 4 | "log" 5 | ) 6 | 7 | // IfMiddleware evaluates at runtime a condition based on the current request, and decides to 8 | // execute one of the other Middleware based on this boolean. 9 | type IfMiddleware struct { 10 | 11 | // Runtime condition that decides of the execution of IfTrue of IfFalse. 12 | Condition func(r *Request) bool 13 | 14 | // Middleware to run when the condition is true. Note that the middleware is initialized 15 | // weather if will be used or not. (Optional, pass-through if not set) 16 | IfTrue Middleware 17 | 18 | // Middleware to run when the condition is false. Note that the middleware is initialized 19 | // weather if will be used or not. (Optional, pass-through if not set) 20 | IfFalse Middleware 21 | } 22 | 23 | // MiddlewareFunc makes TimerMiddleware implement the Middleware interface. 24 | func (mw *IfMiddleware) MiddlewareFunc(h HandlerFunc) HandlerFunc { 25 | 26 | if mw.Condition == nil { 27 | log.Fatal("IfMiddleware Condition is required") 28 | } 29 | 30 | var ifTrueHandler HandlerFunc 31 | if mw.IfTrue != nil { 32 | ifTrueHandler = mw.IfTrue.MiddlewareFunc(h) 33 | } else { 34 | ifTrueHandler = h 35 | } 36 | 37 | var ifFalseHandler HandlerFunc 38 | if mw.IfFalse != nil { 39 | ifFalseHandler = mw.IfFalse.MiddlewareFunc(h) 40 | } else { 41 | ifFalseHandler = h 42 | } 43 | 44 | return func(w ResponseWriter, r *Request) { 45 | 46 | if mw.Condition(r) { 47 | ifTrueHandler(w, r) 48 | } else { 49 | ifFalseHandler(w, r) 50 | } 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /vendor/github.com/ant0ine/go-json-rest/rest/middleware.go: -------------------------------------------------------------------------------- 1 | package rest 2 | 3 | import ( 4 | "net/http" 5 | ) 6 | 7 | // HandlerFunc defines the handler function. It is the go-json-rest equivalent of http.HandlerFunc. 8 | type HandlerFunc func(ResponseWriter, *Request) 9 | 10 | // App defines the interface that an object should implement to be used as an app in this framework 11 | // stack. The App is the top element of the stack, the other elements being middlewares. 12 | type App interface { 13 | AppFunc() HandlerFunc 14 | } 15 | 16 | // AppSimple is an adapter type that makes it easy to write an App with a simple function. 17 | // eg: rest.NewApi(rest.AppSimple(func(w rest.ResponseWriter, r *rest.Request) { ... })) 18 | type AppSimple HandlerFunc 19 | 20 | // AppFunc makes AppSimple implement the App interface. 21 | func (as AppSimple) AppFunc() HandlerFunc { 22 | return HandlerFunc(as) 23 | } 24 | 25 | // Middleware defines the interface that objects must implement in order to wrap a HandlerFunc and 26 | // be used in the middleware stack. 27 | type Middleware interface { 28 | MiddlewareFunc(handler HandlerFunc) HandlerFunc 29 | } 30 | 31 | // MiddlewareSimple is an adapter type that makes it easy to write a Middleware with a simple 32 | // function. eg: api.Use(rest.MiddlewareSimple(func(h HandlerFunc) Handlerfunc { ... })) 33 | type MiddlewareSimple func(handler HandlerFunc) HandlerFunc 34 | 35 | // MiddlewareFunc makes MiddlewareSimple implement the Middleware interface. 36 | func (ms MiddlewareSimple) MiddlewareFunc(handler HandlerFunc) HandlerFunc { 37 | return ms(handler) 38 | } 39 | 40 | // WrapMiddlewares calls the MiddlewareFunc methods in the reverse order and returns an HandlerFunc 41 | // ready to be executed. This can be used to wrap a set of middlewares, post routing, on a per Route 42 | // basis. 43 | func WrapMiddlewares(middlewares []Middleware, handler HandlerFunc) HandlerFunc { 44 | wrapped := handler 45 | for i := len(middlewares) - 1; i >= 0; i-- { 46 | wrapped = middlewares[i].MiddlewareFunc(wrapped) 47 | } 48 | return wrapped 49 | } 50 | 51 | // Handle the transition between net/http and go-json-rest objects. 52 | // It intanciates the rest.Request and rest.ResponseWriter, ... 53 | func adapterFunc(handler HandlerFunc) http.HandlerFunc { 54 | 55 | return func(origWriter http.ResponseWriter, origRequest *http.Request) { 56 | 57 | // instantiate the rest objects 58 | request := &Request{ 59 | origRequest, 60 | nil, 61 | map[string]interface{}{}, 62 | } 63 | 64 | writer := &responseWriter{ 65 | origWriter, 66 | false, 67 | } 68 | 69 | // call the wrapped handler 70 | handler(writer, request) 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /vendor/github.com/ant0ine/go-json-rest/rest/powered_by.go: -------------------------------------------------------------------------------- 1 | package rest 2 | 3 | const xPoweredByDefault = "go-json-rest" 4 | 5 | // PoweredByMiddleware adds the "X-Powered-By" header to the HTTP response. 6 | type PoweredByMiddleware struct { 7 | 8 | // If specified, used as the value for the "X-Powered-By" response header. 9 | // Defaults to "go-json-rest". 10 | XPoweredBy string 11 | } 12 | 13 | // MiddlewareFunc makes PoweredByMiddleware implement the Middleware interface. 14 | func (mw *PoweredByMiddleware) MiddlewareFunc(h HandlerFunc) HandlerFunc { 15 | 16 | poweredBy := xPoweredByDefault 17 | if mw.XPoweredBy != "" { 18 | poweredBy = mw.XPoweredBy 19 | } 20 | 21 | return func(w ResponseWriter, r *Request) { 22 | 23 | w.Header().Add("X-Powered-By", poweredBy) 24 | 25 | // call the handler 26 | h(w, r) 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /vendor/github.com/ant0ine/go-json-rest/rest/recover.go: -------------------------------------------------------------------------------- 1 | package rest 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "log" 7 | "net/http" 8 | "os" 9 | "runtime/debug" 10 | ) 11 | 12 | // RecoverMiddleware catches the panic errors that occur in the wrapped HandleFunc, 13 | // and convert them to 500 responses. 14 | type RecoverMiddleware struct { 15 | 16 | // Custom logger used for logging the panic errors, 17 | // optional, defaults to log.New(os.Stderr, "", 0) 18 | Logger *log.Logger 19 | 20 | // If true, the log records will be printed as JSON. Convenient for log parsing. 21 | EnableLogAsJson bool 22 | 23 | // If true, when a "panic" happens, the error string and the stack trace will be 24 | // printed in the 500 response body. 25 | EnableResponseStackTrace bool 26 | } 27 | 28 | // MiddlewareFunc makes RecoverMiddleware implement the Middleware interface. 29 | func (mw *RecoverMiddleware) MiddlewareFunc(h HandlerFunc) HandlerFunc { 30 | 31 | // set the default Logger 32 | if mw.Logger == nil { 33 | mw.Logger = log.New(os.Stderr, "", 0) 34 | } 35 | 36 | return func(w ResponseWriter, r *Request) { 37 | 38 | // catch user code's panic, and convert to http response 39 | defer func() { 40 | if reco := recover(); reco != nil { 41 | trace := debug.Stack() 42 | 43 | // log the trace 44 | message := fmt.Sprintf("%s\n%s", reco, trace) 45 | mw.logError(message) 46 | 47 | // write error response 48 | if mw.EnableResponseStackTrace { 49 | Error(w, message, http.StatusInternalServerError) 50 | } else { 51 | Error(w, "Internal Server Error", http.StatusInternalServerError) 52 | } 53 | } 54 | }() 55 | 56 | // call the handler 57 | h(w, r) 58 | } 59 | } 60 | 61 | func (mw *RecoverMiddleware) logError(message string) { 62 | if mw.EnableLogAsJson { 63 | record := map[string]string{ 64 | "error": message, 65 | } 66 | b, err := json.Marshal(&record) 67 | if err != nil { 68 | panic(err) 69 | } 70 | mw.Logger.Printf("%s", b) 71 | } else { 72 | mw.Logger.Print(message) 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /vendor/github.com/ant0ine/go-json-rest/rest/timer.go: -------------------------------------------------------------------------------- 1 | package rest 2 | 3 | import ( 4 | "time" 5 | ) 6 | 7 | // TimerMiddleware computes the elapsed time spent during the execution of the wrapped handler. 8 | // The result is available to the wrapping handlers as request.Env["ELAPSED_TIME"].(*time.Duration), 9 | // and as request.Env["START_TIME"].(*time.Time) 10 | type TimerMiddleware struct{} 11 | 12 | // MiddlewareFunc makes TimerMiddleware implement the Middleware interface. 13 | func (mw *TimerMiddleware) MiddlewareFunc(h HandlerFunc) HandlerFunc { 14 | return func(w ResponseWriter, r *Request) { 15 | 16 | start := time.Now() 17 | r.Env["START_TIME"] = &start 18 | 19 | // call the handler 20 | h(w, r) 21 | 22 | end := time.Now() 23 | elapsed := end.Sub(start) 24 | r.Env["ELAPSED_TIME"] = &elapsed 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /vendor/github.com/asaskevich/govalidator/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.1 5 | - 1.2 6 | - 1.3 7 | - 1.4 8 | - 1.5 9 | - 1.6 10 | - tip 11 | 12 | notifications: 13 | email: 14 | - bwatas@gmail.com 15 | -------------------------------------------------------------------------------- /vendor/github.com/asaskevich/govalidator/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Alex Saskevich 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /vendor/github.com/asaskevich/govalidator/arrays.go: -------------------------------------------------------------------------------- 1 | package govalidator 2 | 3 | // Iterator is the function that accepts element of slice/array and its index 4 | type Iterator func(interface{}, int) 5 | 6 | // ResultIterator is the function that accepts element of slice/array and its index and returns any result 7 | type ResultIterator func(interface{}, int) interface{} 8 | 9 | // ConditionIterator is the function that accepts element of slice/array and its index and returns boolean 10 | type ConditionIterator func(interface{}, int) bool 11 | 12 | // Each iterates over the slice and apply Iterator to every item 13 | func Each(array []interface{}, iterator Iterator) { 14 | for index, data := range array { 15 | iterator(data, index) 16 | } 17 | } 18 | 19 | // Map iterates over the slice and apply ResultIterator to every item. Returns new slice as a result. 20 | func Map(array []interface{}, iterator ResultIterator) []interface{} { 21 | var result = make([]interface{}, len(array)) 22 | for index, data := range array { 23 | result[index] = iterator(data, index) 24 | } 25 | return result 26 | } 27 | 28 | // Find iterates over the slice and apply ConditionIterator to every item. Returns first item that meet ConditionIterator or nil otherwise. 29 | func Find(array []interface{}, iterator ConditionIterator) interface{} { 30 | for index, data := range array { 31 | if iterator(data, index) { 32 | return data 33 | } 34 | } 35 | return nil 36 | } 37 | 38 | // Filter iterates over the slice and apply ConditionIterator to every item. Returns new slice. 39 | func Filter(array []interface{}, iterator ConditionIterator) []interface{} { 40 | var result = make([]interface{}, 0) 41 | for index, data := range array { 42 | if iterator(data, index) { 43 | result = append(result, data) 44 | } 45 | } 46 | return result 47 | } 48 | 49 | // Count iterates over the slice and apply ConditionIterator to every item. Returns count of items that meets ConditionIterator. 50 | func Count(array []interface{}, iterator ConditionIterator) int { 51 | count := 0 52 | for index, data := range array { 53 | if iterator(data, index) { 54 | count = count + 1 55 | } 56 | } 57 | return count 58 | } 59 | -------------------------------------------------------------------------------- /vendor/github.com/asaskevich/govalidator/converter.go: -------------------------------------------------------------------------------- 1 | package govalidator 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "reflect" 7 | "strconv" 8 | ) 9 | 10 | // ToString convert the input to a string. 11 | func ToString(obj interface{}) string { 12 | res := fmt.Sprintf("%v", obj) 13 | return string(res) 14 | } 15 | 16 | // ToJSON convert the input to a valid JSON string 17 | func ToJSON(obj interface{}) (string, error) { 18 | res, err := json.Marshal(obj) 19 | if err != nil { 20 | res = []byte("") 21 | } 22 | return string(res), err 23 | } 24 | 25 | // ToFloat convert the input string to a float, or 0.0 if the input is not a float. 26 | func ToFloat(str string) (float64, error) { 27 | res, err := strconv.ParseFloat(str, 64) 28 | if err != nil { 29 | res = 0.0 30 | } 31 | return res, err 32 | } 33 | 34 | // ToInt convert the input string or any int type to an integer type 64, or 0 if the input is not an integer. 35 | func ToInt(value interface{}) (res int64, err error) { 36 | val := reflect.ValueOf(value) 37 | 38 | switch value.(type) { 39 | case int, int8, int16, int32, int64: 40 | res = val.Int() 41 | case uint, uint8, uint16, uint32, uint64: 42 | res = int64(val.Uint()) 43 | case string: 44 | if IsInt(val.String()) { 45 | res, err = strconv.ParseInt(val.String(), 0, 64) 46 | if err != nil { 47 | res = 0 48 | } 49 | } else { 50 | err = fmt.Errorf("math: square root of negative number %g", value) 51 | res = 0 52 | } 53 | default: 54 | err = fmt.Errorf("math: square root of negative number %g", value) 55 | res = 0 56 | } 57 | 58 | return 59 | } 60 | 61 | // ToBoolean convert the input string to a boolean. 62 | func ToBoolean(str string) (bool, error) { 63 | return strconv.ParseBool(str) 64 | } 65 | -------------------------------------------------------------------------------- /vendor/github.com/asaskevich/govalidator/error.go: -------------------------------------------------------------------------------- 1 | package govalidator 2 | 3 | import "strings" 4 | 5 | // Errors is an array of multiple errors and conforms to the error interface. 6 | type Errors []error 7 | 8 | // Errors returns itself. 9 | func (es Errors) Errors() []error { 10 | return es 11 | } 12 | 13 | func (es Errors) Error() string { 14 | var errs []string 15 | for _, e := range es { 16 | errs = append(errs, e.Error()) 17 | } 18 | return strings.Join(errs, ";") 19 | } 20 | 21 | // Error encapsulates a name, an error and whether there's a custom error message or not. 22 | type Error struct { 23 | Name string 24 | Err error 25 | CustomErrorMessageExists bool 26 | 27 | // Validator indicates the name of the validator that failed 28 | Validator string 29 | } 30 | 31 | func (e Error) Error() string { 32 | if e.CustomErrorMessageExists { 33 | return e.Err.Error() 34 | } 35 | return e.Name + ": " + e.Err.Error() 36 | } 37 | -------------------------------------------------------------------------------- /vendor/github.com/asaskevich/govalidator/wercker.yml: -------------------------------------------------------------------------------- 1 | box: golang 2 | build: 3 | steps: 4 | - setup-go-workspace 5 | 6 | - script: 7 | name: go get 8 | code: | 9 | go version 10 | go get -t ./... 11 | 12 | - script: 13 | name: go test 14 | code: | 15 | go test -race ./... 16 | -------------------------------------------------------------------------------- /vendor/github.com/beevik/etree/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | sudo: false 3 | 4 | go: 5 | - 1.5.x 6 | - 1.6.x 7 | - 1.7.x 8 | - 1.8.x 9 | - 1.9.x 10 | - 1.10.x 11 | - tip 12 | 13 | matrix: 14 | allow_failures: 15 | - go: tip 16 | 17 | script: 18 | - go vet ./... 19 | - go test -v ./... 20 | -------------------------------------------------------------------------------- /vendor/github.com/beevik/etree/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | Brett Vickers (beevik) 2 | Felix Geisendörfer (felixge) 3 | Kamil Kisiel (kisielk) 4 | Graham King (grahamking) 5 | Matt Smith (ma314smith) 6 | Michal Jemala (michaljemala) 7 | Nicolas Piganeau (npiganeau) 8 | Chris Brown (ccbrown) 9 | Earncef Sequeira (earncef) -------------------------------------------------------------------------------- /vendor/github.com/beevik/etree/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2015 Brett Vickers. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY COPYRIGHT HOLDER ``AS IS'' AND ANY 15 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER OR 18 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 22 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /vendor/github.com/beevik/etree/RELEASE_NOTES.md: -------------------------------------------------------------------------------- 1 | Release v1.0.1 2 | ============== 3 | 4 | **Changes** 5 | 6 | * Added support for absolute etree Path queries. An absolute path begins with 7 | `/` or `//` and begins its search from the element's document root. 8 | * Added [`GetPath`](https://godoc.org/github.com/beevik/etree#Element.GetPath) 9 | and [`GetRelativePath`](https://godoc.org/github.com/beevik/etree#Element.GetRelativePath) 10 | functions to the [`Element`](https://godoc.org/github.com/beevik/etree#Element) 11 | type. 12 | 13 | **Breaking changes** 14 | 15 | * A path starting with `//` is now interpreted as an absolute path. 16 | Previously, it was interpreted as a relative path starting from the element 17 | whose 18 | [`FindElement`](https://godoc.org/github.com/beevik/etree#Element.FindElement) 19 | method was called. To remain compatible with this release, all paths 20 | prefixed with `//` should be prefixed with `.//` when called from any 21 | element other than the document's root. 22 | 23 | 24 | Release v1.0.0 25 | ============== 26 | 27 | Initial release. 28 | -------------------------------------------------------------------------------- /vendor/github.com/davecgh/go-spew/LICENSE: -------------------------------------------------------------------------------- 1 | ISC License 2 | 3 | Copyright (c) 2012-2016 Dave Collins 4 | 5 | Permission to use, copy, modify, and distribute this software for any 6 | purpose with or without fee is hereby granted, provided that the above 7 | copyright notice and this permission notice appear in all copies. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | -------------------------------------------------------------------------------- /vendor/github.com/davecgh/go-spew/spew/bypasssafe.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2016 Dave Collins 2 | // 3 | // Permission to use, copy, modify, and distribute this software for any 4 | // purpose with or without fee is hereby granted, provided that the above 5 | // copyright notice and this permission notice appear in all copies. 6 | // 7 | // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | // NOTE: Due to the following build constraints, this file will only be compiled 16 | // when the code is running on Google App Engine, compiled by GopherJS, or 17 | // "-tags safe" is added to the go build command line. The "disableunsafe" 18 | // tag is deprecated and thus should not be used. 19 | // +build js appengine safe disableunsafe 20 | 21 | package spew 22 | 23 | import "reflect" 24 | 25 | const ( 26 | // UnsafeDisabled is a build-time constant which specifies whether or 27 | // not access to the unsafe package is available. 28 | UnsafeDisabled = true 29 | ) 30 | 31 | // unsafeReflectValue typically converts the passed reflect.Value into a one 32 | // that bypasses the typical safety restrictions preventing access to 33 | // unaddressable and unexported data. However, doing this relies on access to 34 | // the unsafe package. This is a stub version which simply returns the passed 35 | // reflect.Value when the unsafe package is not available. 36 | func unsafeReflectValue(v reflect.Value) reflect.Value { 37 | return v 38 | } 39 | -------------------------------------------------------------------------------- /vendor/github.com/fatih/camelcase/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go: 1.x 3 | 4 | -------------------------------------------------------------------------------- /vendor/github.com/fatih/camelcase/LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Fatih Arslan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /vendor/github.com/fatih/camelcase/README.md: -------------------------------------------------------------------------------- 1 | # CamelCase [![GoDoc](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](http://godoc.org/github.com/fatih/camelcase) [![Build Status](http://img.shields.io/travis/fatih/camelcase.svg?style=flat-square)](https://travis-ci.org/fatih/camelcase) 2 | 3 | CamelCase is a Golang (Go) package to split the words of a camelcase type 4 | string into a slice of words. It can be used to convert a camelcase word (lower 5 | or upper case) into any type of word. 6 | 7 | ## Splitting rules: 8 | 9 | 1. If string is not valid UTF-8, return it without splitting as 10 | single item array. 11 | 2. Assign all unicode characters into one of 4 sets: lower case 12 | letters, upper case letters, numbers, and all other characters. 13 | 3. Iterate through characters of string, introducing splits 14 | between adjacent characters that belong to different sets. 15 | 4. Iterate through array of split strings, and if a given string 16 | is upper case: 17 | * if subsequent string is lower case: 18 | * move last character of upper case string to beginning of 19 | lower case string 20 | 21 | ## Install 22 | 23 | ```bash 24 | go get github.com/fatih/camelcase 25 | ``` 26 | 27 | ## Usage and examples 28 | 29 | ```go 30 | splitted := camelcase.Split("GolangPackage") 31 | 32 | fmt.Println(splitted[0], splitted[1]) // prints: "Golang", "Package" 33 | ``` 34 | 35 | Both lower camel case and upper camel case are supported. For more info please 36 | check: [http://en.wikipedia.org/wiki/CamelCase](http://en.wikipedia.org/wiki/CamelCase) 37 | 38 | Below are some example cases: 39 | 40 | ``` 41 | "" => [] 42 | "lowercase" => ["lowercase"] 43 | "Class" => ["Class"] 44 | "MyClass" => ["My", "Class"] 45 | "MyC" => ["My", "C"] 46 | "HTML" => ["HTML"] 47 | "PDFLoader" => ["PDF", "Loader"] 48 | "AString" => ["A", "String"] 49 | "SimpleXMLParser" => ["Simple", "XML", "Parser"] 50 | "vimRPCPlugin" => ["vim", "RPC", "Plugin"] 51 | "GL11Version" => ["GL", "11", "Version"] 52 | "99Bottles" => ["99", "Bottles"] 53 | "May5" => ["May", "5"] 54 | "BFG9000" => ["BFG", "9000"] 55 | "BöseÜberraschung" => ["Böse", "Überraschung"] 56 | "Two spaces" => ["Two", " ", "spaces"] 57 | "BadUTF8\xe2\xe2\xa1" => ["BadUTF8\xe2\xe2\xa1"] 58 | ``` 59 | -------------------------------------------------------------------------------- /vendor/github.com/fatih/structs/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | -------------------------------------------------------------------------------- /vendor/github.com/fatih/structs/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go: 3 | - 1.7.x 4 | - tip 5 | sudo: false 6 | before_install: 7 | - go get github.com/axw/gocov/gocov 8 | - go get github.com/mattn/goveralls 9 | - if ! go get github.com/golang/tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi 10 | script: 11 | - $HOME/gopath/bin/goveralls -service=travis-ci 12 | -------------------------------------------------------------------------------- /vendor/github.com/fatih/structs/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Fatih Arslan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /vendor/github.com/fatih/structs/tags.go: -------------------------------------------------------------------------------- 1 | package structs 2 | 3 | import "strings" 4 | 5 | // tagOptions contains a slice of tag options 6 | type tagOptions []string 7 | 8 | // Has returns true if the given optiton is available in tagOptions 9 | func (t tagOptions) Has(opt string) bool { 10 | for _, tagOpt := range t { 11 | if tagOpt == opt { 12 | return true 13 | } 14 | } 15 | 16 | return false 17 | } 18 | 19 | // parseTag splits a struct field's tag into its name and a list of options 20 | // which comes after a name. A tag is in the form of: "name,option1,option2". 21 | // The name can be neglectected. 22 | func parseTag(tag string) (string, tagOptions) { 23 | // tag is one of followings: 24 | // "" 25 | // "name" 26 | // "name,opt" 27 | // "name,opt,opt2" 28 | // ",opt" 29 | 30 | res := strings.Split(tag, ",") 31 | return res[0], res[1:] 32 | } 33 | -------------------------------------------------------------------------------- /vendor/github.com/go-sql-driver/mysql/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .DS_Store? 3 | ._* 4 | .Spotlight-V100 5 | .Trashes 6 | Icon? 7 | ehthumbs.db 8 | Thumbs.db 9 | .idea 10 | -------------------------------------------------------------------------------- /vendor/github.com/go-sql-driver/mysql/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | ## Reporting Issues 4 | 5 | Before creating a new Issue, please check first if a similar Issue [already exists](https://github.com/go-sql-driver/mysql/issues?state=open) or was [recently closed](https://github.com/go-sql-driver/mysql/issues?direction=desc&page=1&sort=updated&state=closed). 6 | 7 | ## Contributing Code 8 | 9 | By contributing to this project, you share your code under the Mozilla Public License 2, as specified in the LICENSE file. 10 | Don't forget to add yourself to the AUTHORS file. 11 | 12 | ### Code Review 13 | 14 | Everyone is invited to review and comment on pull requests. 15 | If it looks fine to you, comment with "LGTM" (Looks good to me). 16 | 17 | If changes are required, notice the reviewers with "PTAL" (Please take another look) after committing the fixes. 18 | 19 | Before merging the Pull Request, at least one [team member](https://github.com/go-sql-driver?tab=members) must have commented with "LGTM". 20 | 21 | ## Development Ideas 22 | 23 | If you are looking for ideas for code contributions, please check our [Development Ideas](https://github.com/go-sql-driver/mysql/wiki/Development-Ideas) Wiki page. 24 | -------------------------------------------------------------------------------- /vendor/github.com/go-sql-driver/mysql/appengine.go: -------------------------------------------------------------------------------- 1 | // Go MySQL Driver - A MySQL-Driver for Go's database/sql package 2 | // 3 | // Copyright 2013 The Go-MySQL-Driver Authors. All rights reserved. 4 | // 5 | // This Source Code Form is subject to the terms of the Mozilla Public 6 | // License, v. 2.0. If a copy of the MPL was not distributed with this file, 7 | // You can obtain one at http://mozilla.org/MPL/2.0/. 8 | 9 | // +build appengine 10 | 11 | package mysql 12 | 13 | import ( 14 | "google.golang.org/appengine/cloudsql" 15 | ) 16 | 17 | func init() { 18 | RegisterDial("cloudsql", cloudsql.Dial) 19 | } 20 | -------------------------------------------------------------------------------- /vendor/github.com/go-sql-driver/mysql/result.go: -------------------------------------------------------------------------------- 1 | // Go MySQL Driver - A MySQL-Driver for Go's database/sql package 2 | // 3 | // Copyright 2012 The Go-MySQL-Driver Authors. All rights reserved. 4 | // 5 | // This Source Code Form is subject to the terms of the Mozilla Public 6 | // License, v. 2.0. If a copy of the MPL was not distributed with this file, 7 | // You can obtain one at http://mozilla.org/MPL/2.0/. 8 | 9 | package mysql 10 | 11 | type mysqlResult struct { 12 | affectedRows int64 13 | insertId int64 14 | } 15 | 16 | func (res *mysqlResult) LastInsertId() (int64, error) { 17 | return res.insertId, nil 18 | } 19 | 20 | func (res *mysqlResult) RowsAffected() (int64, error) { 21 | return res.affectedRows, nil 22 | } 23 | -------------------------------------------------------------------------------- /vendor/github.com/go-sql-driver/mysql/transaction.go: -------------------------------------------------------------------------------- 1 | // Go MySQL Driver - A MySQL-Driver for Go's database/sql package 2 | // 3 | // Copyright 2012 The Go-MySQL-Driver Authors. All rights reserved. 4 | // 5 | // This Source Code Form is subject to the terms of the Mozilla Public 6 | // License, v. 2.0. If a copy of the MPL was not distributed with this file, 7 | // You can obtain one at http://mozilla.org/MPL/2.0/. 8 | 9 | package mysql 10 | 11 | type mysqlTx struct { 12 | mc *mysqlConn 13 | } 14 | 15 | func (tx *mysqlTx) Commit() (err error) { 16 | if tx.mc == nil || tx.mc.closed.IsSet() { 17 | return ErrInvalidConn 18 | } 19 | err = tx.mc.exec("COMMIT") 20 | tx.mc = nil 21 | return 22 | } 23 | 24 | func (tx *mysqlTx) Rollback() (err error) { 25 | if tx.mc == nil || tx.mc.closed.IsSet() { 26 | return ErrInvalidConn 27 | } 28 | err = tx.mc.exec("ROLLBACK") 29 | tx.mc = nil 30 | return 31 | } 32 | -------------------------------------------------------------------------------- /vendor/github.com/go-sql-driver/mysql/utils_go17.go: -------------------------------------------------------------------------------- 1 | // Go MySQL Driver - A MySQL-Driver for Go's database/sql package 2 | // 3 | // Copyright 2017 The Go-MySQL-Driver Authors. All rights reserved. 4 | // 5 | // This Source Code Form is subject to the terms of the Mozilla Public 6 | // License, v. 2.0. If a copy of the MPL was not distributed with this file, 7 | // You can obtain one at http://mozilla.org/MPL/2.0/. 8 | 9 | // +build go1.7 10 | // +build !go1.8 11 | 12 | package mysql 13 | 14 | import "crypto/tls" 15 | 16 | func cloneTLSConfig(c *tls.Config) *tls.Config { 17 | return &tls.Config{ 18 | Rand: c.Rand, 19 | Time: c.Time, 20 | Certificates: c.Certificates, 21 | NameToCertificate: c.NameToCertificate, 22 | GetCertificate: c.GetCertificate, 23 | RootCAs: c.RootCAs, 24 | NextProtos: c.NextProtos, 25 | ServerName: c.ServerName, 26 | ClientAuth: c.ClientAuth, 27 | ClientCAs: c.ClientCAs, 28 | InsecureSkipVerify: c.InsecureSkipVerify, 29 | CipherSuites: c.CipherSuites, 30 | PreferServerCipherSuites: c.PreferServerCipherSuites, 31 | SessionTicketsDisabled: c.SessionTicketsDisabled, 32 | SessionTicketKey: c.SessionTicketKey, 33 | ClientSessionCache: c.ClientSessionCache, 34 | MinVersion: c.MinVersion, 35 | MaxVersion: c.MaxVersion, 36 | CurvePreferences: c.CurvePreferences, 37 | DynamicRecordSizingDisabled: c.DynamicRecordSizingDisabled, 38 | Renegotiation: c.Renegotiation, 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /vendor/github.com/go-sql-driver/mysql/utils_go18.go: -------------------------------------------------------------------------------- 1 | // Go MySQL Driver - A MySQL-Driver for Go's database/sql package 2 | // 3 | // Copyright 2017 The Go-MySQL-Driver Authors. All rights reserved. 4 | // 5 | // This Source Code Form is subject to the terms of the Mozilla Public 6 | // License, v. 2.0. If a copy of the MPL was not distributed with this file, 7 | // You can obtain one at http://mozilla.org/MPL/2.0/. 8 | 9 | // +build go1.8 10 | 11 | package mysql 12 | 13 | import ( 14 | "crypto/tls" 15 | "database/sql" 16 | "database/sql/driver" 17 | "errors" 18 | "fmt" 19 | ) 20 | 21 | func cloneTLSConfig(c *tls.Config) *tls.Config { 22 | return c.Clone() 23 | } 24 | 25 | func namedValueToValue(named []driver.NamedValue) ([]driver.Value, error) { 26 | dargs := make([]driver.Value, len(named)) 27 | for n, param := range named { 28 | if len(param.Name) > 0 { 29 | // TODO: support the use of Named Parameters #561 30 | return nil, errors.New("mysql: driver does not support the use of Named Parameters") 31 | } 32 | dargs[n] = param.Value 33 | } 34 | return dargs, nil 35 | } 36 | 37 | func mapIsolationLevel(level driver.IsolationLevel) (string, error) { 38 | switch sql.IsolationLevel(level) { 39 | case sql.LevelRepeatableRead: 40 | return "REPEATABLE READ", nil 41 | case sql.LevelReadCommitted: 42 | return "READ COMMITTED", nil 43 | case sql.LevelReadUncommitted: 44 | return "READ UNCOMMITTED", nil 45 | case sql.LevelSerializable: 46 | return "SERIALIZABLE", nil 47 | default: 48 | return "", fmt.Errorf("mysql: unsupported isolation level: %v", level) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /vendor/github.com/gocraft/dbr/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change log 2 | 3 | Not all minor changes may be noted here, but all large and/or breaking changes 4 | should be. 5 | 6 | ## v2.0 - 2015-10-09 7 | 8 | ### Added 9 | - PostgreSQL support! 10 | - `Open(driver, dsn string, log EventReceiver)` creates an underlying connection for you based on a supplied driver and dsn string 11 | - All builders are now available without a `Session` facilitating much more complex queries 12 | - More common SQL support: Subqueries, Unions, Joins, Aliases 13 | - More complex condition building support: And/Or/Eq/Neq/Gt/Gte/Lt/Lte 14 | 15 | ### Deprecated 16 | - `NewConnection` is deprecated. It assumes MySQL driver. Please use `Open` instead 17 | 18 | ### Changed 19 | - `NullTime` no longer relies on the mysql package. E.g. instead of `NullTime{mysql.NullTime{Time: t, Valid: true}}` it's now simply `NullTime{Time: t, Valid: true}` 20 | - All `*Builder` structs now embed a corresponding `*Stmt` struct (E.g. `SelectBuilder` embeds `SelectStmt`). All non-`Session` specific properies have been moved the `*Stmt` structs 21 | -------------------------------------------------------------------------------- /vendor/github.com/gocraft/dbr/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2017 Jonathan Novak, Tai-Lin Chu 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /vendor/github.com/gocraft/dbr/buffer.go: -------------------------------------------------------------------------------- 1 | package dbr 2 | 3 | import "bytes" 4 | 5 | type Buffer interface { 6 | WriteString(s string) (n int, err error) 7 | String() string 8 | 9 | WriteValue(v ...interface{}) (err error) 10 | Value() []interface{} 11 | } 12 | 13 | type buffer struct { 14 | bytes.Buffer 15 | v []interface{} 16 | } 17 | 18 | func NewBuffer() Buffer { 19 | return &buffer{} 20 | } 21 | 22 | func (b *buffer) WriteValue(v ...interface{}) error { 23 | b.v = append(b.v, v...) 24 | return nil 25 | } 26 | 27 | func (b *buffer) Value() []interface{} { 28 | return b.v 29 | } 30 | -------------------------------------------------------------------------------- /vendor/github.com/gocraft/dbr/builder.go: -------------------------------------------------------------------------------- 1 | package dbr 2 | 3 | // Builder builds sql in one dialect like MySQL/PostgreSQL 4 | // e.g. XxxBuilder 5 | type Builder interface { 6 | Build(Dialect, Buffer) error 7 | } 8 | 9 | type BuildFunc func(Dialect, Buffer) error 10 | 11 | func (b BuildFunc) Build(d Dialect, buf Buffer) error { 12 | return b(d, buf) 13 | } 14 | -------------------------------------------------------------------------------- /vendor/github.com/gocraft/dbr/delete.go: -------------------------------------------------------------------------------- 1 | package dbr 2 | 3 | // DeleteStmt builds `DELETE ...` 4 | type DeleteStmt struct { 5 | raw 6 | 7 | Table string 8 | 9 | WhereCond []Builder 10 | } 11 | 12 | // Build builds `DELETE ...` in dialect 13 | func (b *DeleteStmt) Build(d Dialect, buf Buffer) error { 14 | if b.raw.Query != "" { 15 | return b.raw.Build(d, buf) 16 | } 17 | 18 | if b.Table == "" { 19 | return ErrTableNotSpecified 20 | } 21 | 22 | buf.WriteString("DELETE FROM ") 23 | buf.WriteString(d.QuoteIdent(b.Table)) 24 | 25 | if len(b.WhereCond) > 0 { 26 | buf.WriteString(" WHERE ") 27 | err := And(b.WhereCond...).Build(d, buf) 28 | if err != nil { 29 | return err 30 | } 31 | } 32 | return nil 33 | } 34 | 35 | // DeleteFrom creates a DeleteStmt 36 | func DeleteFrom(table string) *DeleteStmt { 37 | return &DeleteStmt{ 38 | Table: table, 39 | } 40 | } 41 | 42 | // DeleteBySql creates a DeleteStmt from raw query 43 | func DeleteBySql(query string, value ...interface{}) *DeleteStmt { 44 | return &DeleteStmt{ 45 | raw: raw{ 46 | Query: query, 47 | Value: value, 48 | }, 49 | } 50 | } 51 | 52 | // Where adds a where condition 53 | func (b *DeleteStmt) Where(query interface{}, value ...interface{}) *DeleteStmt { 54 | switch query := query.(type) { 55 | case string: 56 | b.WhereCond = append(b.WhereCond, Expr(query, value...)) 57 | case Builder: 58 | b.WhereCond = append(b.WhereCond, query) 59 | } 60 | return b 61 | } 62 | -------------------------------------------------------------------------------- /vendor/github.com/gocraft/dbr/delete_builder.go: -------------------------------------------------------------------------------- 1 | package dbr 2 | 3 | import ( 4 | "context" 5 | "database/sql" 6 | "fmt" 7 | ) 8 | 9 | type DeleteBuilder struct { 10 | runner 11 | EventReceiver 12 | Dialect Dialect 13 | 14 | *DeleteStmt 15 | 16 | LimitCount int64 17 | } 18 | 19 | func (sess *Session) DeleteFrom(table string) *DeleteBuilder { 20 | return &DeleteBuilder{ 21 | runner: sess, 22 | EventReceiver: sess, 23 | Dialect: sess.Dialect, 24 | DeleteStmt: DeleteFrom(table), 25 | LimitCount: -1, 26 | } 27 | } 28 | 29 | func (tx *Tx) DeleteFrom(table string) *DeleteBuilder { 30 | return &DeleteBuilder{ 31 | runner: tx, 32 | EventReceiver: tx, 33 | Dialect: tx.Dialect, 34 | DeleteStmt: DeleteFrom(table), 35 | LimitCount: -1, 36 | } 37 | } 38 | 39 | func (sess *Session) DeleteBySql(query string, value ...interface{}) *DeleteBuilder { 40 | return &DeleteBuilder{ 41 | runner: sess, 42 | EventReceiver: sess, 43 | Dialect: sess.Dialect, 44 | DeleteStmt: DeleteBySql(query, value...), 45 | LimitCount: -1, 46 | } 47 | } 48 | 49 | func (tx *Tx) DeleteBySql(query string, value ...interface{}) *DeleteBuilder { 50 | return &DeleteBuilder{ 51 | runner: tx, 52 | EventReceiver: tx, 53 | Dialect: tx.Dialect, 54 | DeleteStmt: DeleteBySql(query, value...), 55 | LimitCount: -1, 56 | } 57 | } 58 | 59 | func (b *DeleteBuilder) Exec() (sql.Result, error) { 60 | return b.ExecContext(context.Background()) 61 | } 62 | 63 | func (b *DeleteBuilder) ExecContext(ctx context.Context) (sql.Result, error) { 64 | return exec(ctx, b.runner, b.EventReceiver, b, b.Dialect) 65 | } 66 | 67 | func (b *DeleteBuilder) Where(query interface{}, value ...interface{}) *DeleteBuilder { 68 | b.DeleteStmt.Where(query, value...) 69 | return b 70 | } 71 | 72 | func (b *DeleteBuilder) Limit(n uint64) *DeleteBuilder { 73 | b.LimitCount = int64(n) 74 | return b 75 | } 76 | 77 | func (b *DeleteBuilder) Build(d Dialect, buf Buffer) error { 78 | err := b.DeleteStmt.Build(b.Dialect, buf) 79 | if err != nil { 80 | return err 81 | } 82 | if b.LimitCount >= 0 { 83 | buf.WriteString(" LIMIT ") 84 | buf.WriteString(fmt.Sprint(b.LimitCount)) 85 | } 86 | return nil 87 | } 88 | -------------------------------------------------------------------------------- /vendor/github.com/gocraft/dbr/dialect.go: -------------------------------------------------------------------------------- 1 | package dbr 2 | 3 | import "time" 4 | 5 | // Dialect abstracts database differences 6 | type Dialect interface { 7 | QuoteIdent(id string) string 8 | 9 | EncodeString(s string) string 10 | EncodeBool(b bool) string 11 | EncodeTime(t time.Time) string 12 | EncodeBytes(b []byte) string 13 | 14 | Placeholder(n int) string 15 | } 16 | -------------------------------------------------------------------------------- /vendor/github.com/gocraft/dbr/dialect/dialect.go: -------------------------------------------------------------------------------- 1 | package dialect 2 | 3 | import "strings" 4 | 5 | var ( 6 | // MySQL dialect 7 | MySQL = mysql{} 8 | // PostgreSQL dialect 9 | PostgreSQL = postgreSQL{} 10 | // SQLite3 dialect 11 | SQLite3 = sqlite3{} 12 | ) 13 | 14 | const ( 15 | timeFormat = "2006-01-02 15:04:05.000000" 16 | ) 17 | 18 | func quoteIdent(s, quote string) string { 19 | part := strings.SplitN(s, ".", 2) 20 | if len(part) == 2 { 21 | return quoteIdent(part[0], quote) + "." + quoteIdent(part[1], quote) 22 | } 23 | return quote + s + quote 24 | } 25 | -------------------------------------------------------------------------------- /vendor/github.com/gocraft/dbr/dialect/mysql.go: -------------------------------------------------------------------------------- 1 | package dialect 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "time" 7 | ) 8 | 9 | type mysql struct{} 10 | 11 | func (d mysql) QuoteIdent(s string) string { 12 | return quoteIdent(s, "`") 13 | } 14 | 15 | func (d mysql) EncodeString(s string) string { 16 | buf := new(bytes.Buffer) 17 | 18 | buf.WriteRune('\'') 19 | // https://dev.mysql.com/doc/refman/5.7/en/string-literals.html 20 | for i := 0; i < len(s); i++ { 21 | switch s[i] { 22 | case 0: 23 | buf.WriteString(`\0`) 24 | case '\'': 25 | buf.WriteString(`\'`) 26 | case '"': 27 | buf.WriteString(`\"`) 28 | case '\b': 29 | buf.WriteString(`\b`) 30 | case '\n': 31 | buf.WriteString(`\n`) 32 | case '\r': 33 | buf.WriteString(`\r`) 34 | case '\t': 35 | buf.WriteString(`\t`) 36 | case 26: 37 | buf.WriteString(`\Z`) 38 | case '\\': 39 | buf.WriteString(`\\`) 40 | default: 41 | buf.WriteByte(s[i]) 42 | } 43 | } 44 | 45 | buf.WriteRune('\'') 46 | return buf.String() 47 | } 48 | 49 | func (d mysql) EncodeBool(b bool) string { 50 | if b { 51 | return "1" 52 | } 53 | return "0" 54 | } 55 | 56 | func (d mysql) EncodeTime(t time.Time) string { 57 | return `'` + t.UTC().Format(timeFormat) + `'` 58 | } 59 | 60 | func (d mysql) EncodeBytes(b []byte) string { 61 | return fmt.Sprintf(`0x%x`, b) 62 | } 63 | 64 | func (d mysql) Placeholder(_ int) string { 65 | return "?" 66 | } 67 | -------------------------------------------------------------------------------- /vendor/github.com/gocraft/dbr/dialect/postgresql.go: -------------------------------------------------------------------------------- 1 | package dialect 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | "time" 7 | ) 8 | 9 | type postgreSQL struct{} 10 | 11 | func (d postgreSQL) QuoteIdent(s string) string { 12 | return quoteIdent(s, `"`) 13 | } 14 | 15 | func (d postgreSQL) EncodeString(s string) string { 16 | // http://www.postgresql.org/docs/9.2/static/sql-syntax-lexical.html 17 | return `'` + strings.Replace(s, `'`, `''`, -1) + `'` 18 | } 19 | 20 | func (d postgreSQL) EncodeBool(b bool) string { 21 | if b { 22 | return "TRUE" 23 | } 24 | return "FALSE" 25 | } 26 | 27 | func (d postgreSQL) EncodeTime(t time.Time) string { 28 | return MySQL.EncodeTime(t) 29 | } 30 | 31 | func (d postgreSQL) EncodeBytes(b []byte) string { 32 | return fmt.Sprintf(`E'\\x%x'`, b) 33 | } 34 | 35 | func (d postgreSQL) Placeholder(n int) string { 36 | return fmt.Sprintf("$%d", n+1) 37 | } 38 | -------------------------------------------------------------------------------- /vendor/github.com/gocraft/dbr/dialect/sqlite3.go: -------------------------------------------------------------------------------- 1 | package dialect 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | "time" 7 | ) 8 | 9 | type sqlite3 struct{} 10 | 11 | func (d sqlite3) QuoteIdent(s string) string { 12 | return quoteIdent(s, `"`) 13 | } 14 | 15 | func (d sqlite3) EncodeString(s string) string { 16 | // https://www.sqlite.org/faq.html 17 | return `'` + strings.Replace(s, `'`, `''`, -1) + `'` 18 | } 19 | 20 | func (d sqlite3) EncodeBool(b bool) string { 21 | // https://www.sqlite.org/lang_expr.html 22 | if b { 23 | return "1" 24 | } 25 | return "0" 26 | } 27 | 28 | func (d sqlite3) EncodeTime(t time.Time) string { 29 | // https://www.sqlite.org/lang_datefunc.html 30 | return MySQL.EncodeTime(t) 31 | } 32 | 33 | func (d sqlite3) EncodeBytes(b []byte) string { 34 | // https://www.sqlite.org/lang_expr.html 35 | return fmt.Sprintf(`X'%x'`, b) 36 | } 37 | 38 | func (d sqlite3) Placeholder(_ int) string { 39 | return "?" 40 | } 41 | -------------------------------------------------------------------------------- /vendor/github.com/gocraft/dbr/errors.go: -------------------------------------------------------------------------------- 1 | package dbr 2 | 3 | import "errors" 4 | 5 | // package errors 6 | var ( 7 | ErrNotFound = errors.New("dbr: not found") 8 | ErrNotSupported = errors.New("dbr: not supported") 9 | ErrTableNotSpecified = errors.New("dbr: table not specified") 10 | ErrColumnNotSpecified = errors.New("dbr: column not specified") 11 | ErrInvalidPointer = errors.New("dbr: attempt to load into an invalid pointer") 12 | ErrPlaceholderCount = errors.New("dbr: wrong placeholder count") 13 | ErrInvalidSliceLength = errors.New("dbr: length of slice is 0. length must be >= 1") 14 | ErrCantConvertToTime = errors.New("dbr: can't convert to time.Time") 15 | ErrInvalidTimestring = errors.New("dbr: invalid time string") 16 | ) 17 | -------------------------------------------------------------------------------- /vendor/github.com/gocraft/dbr/event.go: -------------------------------------------------------------------------------- 1 | package dbr 2 | 3 | // EventReceiver gets events from dbr methods for logging purposes 4 | type EventReceiver interface { 5 | Event(eventName string) 6 | EventKv(eventName string, kvs map[string]string) 7 | EventErr(eventName string, err error) error 8 | EventErrKv(eventName string, err error, kvs map[string]string) error 9 | Timing(eventName string, nanoseconds int64) 10 | TimingKv(eventName string, nanoseconds int64, kvs map[string]string) 11 | } 12 | 13 | type kvs map[string]string 14 | 15 | var nullReceiver = &NullEventReceiver{} 16 | 17 | // NullEventReceiver is a sentinel EventReceiver; use it if the caller doesn't supply one 18 | type NullEventReceiver struct{} 19 | 20 | // Event receives a simple notification when various events occur 21 | func (n *NullEventReceiver) Event(eventName string) {} 22 | 23 | // EventKv receives a notification when various events occur along with 24 | // optional key/value data 25 | func (n *NullEventReceiver) EventKv(eventName string, kvs map[string]string) {} 26 | 27 | // EventErr receives a notification of an error if one occurs 28 | func (n *NullEventReceiver) EventErr(eventName string, err error) error { return err } 29 | 30 | // EventErrKv receives a notification of an error if one occurs along with 31 | // optional key/value data 32 | func (n *NullEventReceiver) EventErrKv(eventName string, err error, kvs map[string]string) error { 33 | return err 34 | } 35 | 36 | // Timing receives the time an event took to happen 37 | func (n *NullEventReceiver) Timing(eventName string, nanoseconds int64) {} 38 | 39 | // TimingKv receives the time an event took to happen along with optional key/value data 40 | func (n *NullEventReceiver) TimingKv(eventName string, nanoseconds int64, kvs map[string]string) {} 41 | -------------------------------------------------------------------------------- /vendor/github.com/gocraft/dbr/expr.go: -------------------------------------------------------------------------------- 1 | package dbr 2 | 3 | // XxxBuilders all support raw query 4 | type raw struct { 5 | Query string 6 | Value []interface{} 7 | } 8 | 9 | // Expr should be used when sql syntax is not supported 10 | func Expr(query string, value ...interface{}) Builder { 11 | return &raw{Query: query, Value: value} 12 | } 13 | 14 | func (raw *raw) Build(_ Dialect, buf Buffer) error { 15 | buf.WriteString(raw.Query) 16 | buf.WriteValue(raw.Value...) 17 | return nil 18 | } 19 | -------------------------------------------------------------------------------- /vendor/github.com/gocraft/dbr/ident.go: -------------------------------------------------------------------------------- 1 | package dbr 2 | 3 | // identifier is a type of string 4 | type I string 5 | 6 | func (i I) Build(d Dialect, buf Buffer) error { 7 | buf.WriteString(d.QuoteIdent(string(i))) 8 | return nil 9 | } 10 | 11 | // As creates an alias for expr. e.g. SELECT `a1` AS `a2` 12 | func (i I) As(alias string) Builder { 13 | return as(i, alias) 14 | } 15 | 16 | func as(expr interface{}, alias string) Builder { 17 | return BuildFunc(func(d Dialect, buf Buffer) error { 18 | buf.WriteString(placeholder) 19 | buf.WriteValue(expr) 20 | buf.WriteString(" AS ") 21 | buf.WriteString(d.QuoteIdent(alias)) 22 | return nil 23 | }) 24 | } 25 | -------------------------------------------------------------------------------- /vendor/github.com/gocraft/dbr/join.go: -------------------------------------------------------------------------------- 1 | package dbr 2 | 3 | type joinType uint8 4 | 5 | const ( 6 | inner joinType = iota 7 | left 8 | right 9 | full 10 | ) 11 | 12 | func join(t joinType, table interface{}, on interface{}) Builder { 13 | return BuildFunc(func(d Dialect, buf Buffer) error { 14 | buf.WriteString(" ") 15 | switch t { 16 | case left: 17 | buf.WriteString("LEFT ") 18 | case right: 19 | buf.WriteString("RIGHT ") 20 | case full: 21 | buf.WriteString("FULL ") 22 | } 23 | buf.WriteString("JOIN ") 24 | switch table := table.(type) { 25 | case string: 26 | buf.WriteString(d.QuoteIdent(table)) 27 | default: 28 | buf.WriteString(placeholder) 29 | buf.WriteValue(table) 30 | } 31 | buf.WriteString(" ON ") 32 | switch on := on.(type) { 33 | case string: 34 | buf.WriteString(on) 35 | case Builder: 36 | buf.WriteString(placeholder) 37 | buf.WriteValue(on) 38 | } 39 | return nil 40 | }) 41 | } 42 | -------------------------------------------------------------------------------- /vendor/github.com/gocraft/dbr/now.go: -------------------------------------------------------------------------------- 1 | package dbr 2 | 3 | import ( 4 | "database/sql/driver" 5 | "time" 6 | ) 7 | 8 | // Now is a value that serializes to the current time 9 | var Now = nowSentinel{} 10 | 11 | const timeFormat = "2006-01-02 15:04:05.000000" 12 | 13 | type nowSentinel struct{} 14 | 15 | // Value implements a valuer for compatibility 16 | func (n nowSentinel) Value() (driver.Value, error) { 17 | now := time.Now().UTC().Format(timeFormat) 18 | return now, nil 19 | } 20 | -------------------------------------------------------------------------------- /vendor/github.com/gocraft/dbr/order.go: -------------------------------------------------------------------------------- 1 | package dbr 2 | 3 | type direction bool 4 | 5 | // orderby directions 6 | // most databases by default use asc 7 | const ( 8 | asc direction = false 9 | desc = true 10 | ) 11 | 12 | func order(column string, dir direction) Builder { 13 | return BuildFunc(func(d Dialect, buf Buffer) error { 14 | // FIXME: no quote ident 15 | buf.WriteString(column) 16 | switch dir { 17 | case asc: 18 | buf.WriteString(" ASC") 19 | case desc: 20 | buf.WriteString(" DESC") 21 | } 22 | return nil 23 | }) 24 | } 25 | -------------------------------------------------------------------------------- /vendor/github.com/gocraft/dbr/select_return.go: -------------------------------------------------------------------------------- 1 | package dbr 2 | 3 | // 4 | // These are a set of helpers that just call LoadValue and return the value. 5 | // They return (_, ErrNotFound) if nothing was found. 6 | // 7 | 8 | // The inclusion of these helpers in the package is not an obvious choice: 9 | // Benefits: 10 | // - slight increase in code clarity/conciseness b/c you can use ":=" to define the variable 11 | // 12 | // count, err := d.Select("COUNT(*)").From("users").Where("x = ?", x).ReturnInt64() 13 | // 14 | // vs 15 | // 16 | // var count int64 17 | // err := d.Select("COUNT(*)").From("users").Where("x = ?", x).LoadValue(&count) 18 | // 19 | // Downsides: 20 | // - very small increase in code cost, although it's not complex code 21 | // - increase in conceptual model / API footprint when presenting the package to new users 22 | // - no functionality that you can't achieve calling .LoadValue directly. 23 | // - There's a lot of possible types. Do we want to include ALL of them? u?int{8,16,32,64}?, strings, null varieties, etc. 24 | // - Let's just do the common, non-null varieties. 25 | 26 | // ReturnInt64 executes the SelectStmt and returns the value as an int64 27 | func (b *SelectBuilder) ReturnInt64() (int64, error) { 28 | var v int64 29 | err := b.LoadValue(&v) 30 | return v, err 31 | } 32 | 33 | // ReturnInt64s executes the SelectStmt and returns the value as a slice of int64s 34 | func (b *SelectBuilder) ReturnInt64s() ([]int64, error) { 35 | var v []int64 36 | _, err := b.LoadValues(&v) 37 | return v, err 38 | } 39 | 40 | // ReturnUint64 executes the SelectStmt and returns the value as an uint64 41 | func (b *SelectBuilder) ReturnUint64() (uint64, error) { 42 | var v uint64 43 | err := b.LoadValue(&v) 44 | return v, err 45 | } 46 | 47 | // ReturnUint64s executes the SelectStmt and returns the value as a slice of uint64s 48 | func (b *SelectBuilder) ReturnUint64s() ([]uint64, error) { 49 | var v []uint64 50 | _, err := b.LoadValues(&v) 51 | return v, err 52 | } 53 | 54 | // ReturnString executes the SelectStmt and returns the value as a string 55 | func (b *SelectBuilder) ReturnString() (string, error) { 56 | var v string 57 | err := b.LoadValue(&v) 58 | return v, err 59 | } 60 | 61 | // ReturnStrings executes the SelectStmt and returns the value as a slice of strings 62 | func (b *SelectBuilder) ReturnStrings() ([]string, error) { 63 | var v []string 64 | _, err := b.LoadValues(&v) 65 | return v, err 66 | } 67 | -------------------------------------------------------------------------------- /vendor/github.com/gocraft/dbr/transaction.go: -------------------------------------------------------------------------------- 1 | package dbr 2 | 3 | import ( 4 | "context" 5 | "database/sql" 6 | "time" 7 | ) 8 | 9 | // Tx is a transaction for the given Session 10 | type Tx struct { 11 | EventReceiver 12 | Dialect Dialect 13 | *sql.Tx 14 | Timeout time.Duration 15 | 16 | // normally we don't call the context cancelFunc. 17 | // however, if we start a tx without explictly tx, 18 | // we will need to call this after the transaction. 19 | Cancel func() 20 | } 21 | 22 | func (tx *Tx) GetTimeout() time.Duration { 23 | return tx.Timeout 24 | } 25 | 26 | func (sess *Session) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) { 27 | tx, err := sess.Connection.BeginTx(ctx, opts) 28 | if err != nil { 29 | return nil, sess.EventErr("dbr.begin.error", err) 30 | } 31 | sess.Event("dbr.begin") 32 | 33 | stx := &Tx{ 34 | EventReceiver: sess, 35 | Dialect: sess.Dialect, 36 | Tx: tx, 37 | Cancel: func() {}, 38 | } 39 | deadline, ok := ctx.Deadline() 40 | if ok { 41 | stx.Timeout = deadline.Sub(time.Now()) 42 | } 43 | return stx, nil 44 | } 45 | 46 | // Begin creates a transaction for the given session 47 | func (sess *Session) Begin() (*Tx, error) { 48 | ctx := context.Background() 49 | var cancel func() 50 | timeout := sess.GetTimeout() 51 | if timeout > 0 { 52 | ctx, cancel = context.WithTimeout(ctx, timeout) 53 | } 54 | stx, err := sess.BeginTx(ctx, nil) 55 | if err != nil { 56 | return nil, err 57 | } 58 | if cancel != nil { 59 | stx.Cancel = cancel 60 | } 61 | return stx, nil 62 | } 63 | 64 | // Commit finishes the transaction 65 | func (tx *Tx) Commit() error { 66 | defer tx.Cancel() 67 | err := tx.Tx.Commit() 68 | if err != nil { 69 | return tx.EventErr("dbr.commit.error", err) 70 | } 71 | tx.Event("dbr.commit") 72 | return nil 73 | } 74 | 75 | // Rollback cancels the transaction 76 | func (tx *Tx) Rollback() error { 77 | defer tx.Cancel() 78 | err := tx.Tx.Rollback() 79 | if err != nil { 80 | return tx.EventErr("dbr.rollback", err) 81 | } 82 | tx.Event("dbr.rollback") 83 | return nil 84 | } 85 | 86 | // RollbackUnlessCommitted rollsback the transaction unless it has already been committed or rolled back. 87 | // Useful to defer tx.RollbackUnlessCommitted() -- so you don't have to handle N failure cases 88 | // Keep in mind the only way to detect an error on the rollback is via the event log. 89 | func (tx *Tx) RollbackUnlessCommitted() { 90 | defer tx.Cancel() 91 | err := tx.Tx.Rollback() 92 | if err == sql.ErrTxDone { 93 | // ok 94 | } else if err != nil { 95 | tx.EventErr("dbr.rollback_unless_committed", err) 96 | } else { 97 | tx.Event("dbr.rollback") 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /vendor/github.com/gocraft/dbr/union.go: -------------------------------------------------------------------------------- 1 | package dbr 2 | 3 | type union struct { 4 | builder []Builder 5 | all bool 6 | } 7 | 8 | func Union(builder ...Builder) interface { 9 | Builder 10 | As(string) Builder 11 | } { 12 | return &union{ 13 | builder: builder, 14 | } 15 | } 16 | 17 | func UnionAll(builder ...Builder) interface { 18 | Builder 19 | As(string) Builder 20 | } { 21 | return &union{ 22 | builder: builder, 23 | all: true, 24 | } 25 | } 26 | 27 | func (u *union) Build(d Dialect, buf Buffer) error { 28 | for i, b := range u.builder { 29 | if i > 0 { 30 | buf.WriteString(" UNION ") 31 | if u.all { 32 | buf.WriteString("ALL ") 33 | } 34 | } 35 | buf.WriteString(placeholder) 36 | buf.WriteValue(b) 37 | } 38 | return nil 39 | } 40 | 41 | func (u *union) As(alias string) Builder { 42 | return as(u, alias) 43 | } 44 | -------------------------------------------------------------------------------- /vendor/github.com/gocraft/dbr/update.go: -------------------------------------------------------------------------------- 1 | package dbr 2 | 3 | // UpdateStmt builds `UPDATE ...` 4 | type UpdateStmt struct { 5 | raw 6 | 7 | Table string 8 | Value map[string]interface{} 9 | 10 | WhereCond []Builder 11 | } 12 | 13 | // Build builds `UPDATE ...` in dialect 14 | func (b *UpdateStmt) Build(d Dialect, buf Buffer) error { 15 | if b.raw.Query != "" { 16 | return b.raw.Build(d, buf) 17 | } 18 | 19 | if b.Table == "" { 20 | return ErrTableNotSpecified 21 | } 22 | 23 | if len(b.Value) == 0 { 24 | return ErrColumnNotSpecified 25 | } 26 | 27 | buf.WriteString("UPDATE ") 28 | buf.WriteString(d.QuoteIdent(b.Table)) 29 | buf.WriteString(" SET ") 30 | 31 | i := 0 32 | for col, v := range b.Value { 33 | if i > 0 { 34 | buf.WriteString(", ") 35 | } 36 | buf.WriteString(d.QuoteIdent(col)) 37 | buf.WriteString(" = ") 38 | buf.WriteString(placeholder) 39 | 40 | buf.WriteValue(v) 41 | i++ 42 | } 43 | 44 | if len(b.WhereCond) > 0 { 45 | buf.WriteString(" WHERE ") 46 | err := And(b.WhereCond...).Build(d, buf) 47 | if err != nil { 48 | return err 49 | } 50 | } 51 | return nil 52 | } 53 | 54 | // Update creates an UpdateStmt 55 | func Update(table string) *UpdateStmt { 56 | return &UpdateStmt{ 57 | Table: table, 58 | Value: make(map[string]interface{}), 59 | } 60 | } 61 | 62 | // UpdateBySql creates an UpdateStmt with raw query 63 | func UpdateBySql(query string, value ...interface{}) *UpdateStmt { 64 | return &UpdateStmt{ 65 | raw: raw{ 66 | Query: query, 67 | Value: value, 68 | }, 69 | Value: make(map[string]interface{}), 70 | } 71 | } 72 | 73 | // Where adds a where condition 74 | func (b *UpdateStmt) Where(query interface{}, value ...interface{}) *UpdateStmt { 75 | switch query := query.(type) { 76 | case string: 77 | b.WhereCond = append(b.WhereCond, Expr(query, value...)) 78 | case Builder: 79 | b.WhereCond = append(b.WhereCond, query) 80 | } 81 | return b 82 | } 83 | 84 | // Set specifies a key-value pair 85 | func (b *UpdateStmt) Set(column string, value interface{}) *UpdateStmt { 86 | b.Value[column] = value 87 | return b 88 | } 89 | 90 | // SetMap specifies a list of key-value pair 91 | func (b *UpdateStmt) SetMap(m map[string]interface{}) *UpdateStmt { 92 | for col, val := range m { 93 | b.Set(col, val) 94 | } 95 | return b 96 | } 97 | -------------------------------------------------------------------------------- /vendor/github.com/gocraft/dbr/update_builder.go: -------------------------------------------------------------------------------- 1 | package dbr 2 | 3 | import ( 4 | "context" 5 | "database/sql" 6 | "fmt" 7 | ) 8 | 9 | type UpdateBuilder struct { 10 | runner 11 | EventReceiver 12 | Dialect Dialect 13 | 14 | *UpdateStmt 15 | 16 | LimitCount int64 17 | } 18 | 19 | func (sess *Session) Update(table string) *UpdateBuilder { 20 | return &UpdateBuilder{ 21 | runner: sess, 22 | EventReceiver: sess, 23 | Dialect: sess.Dialect, 24 | UpdateStmt: Update(table), 25 | LimitCount: -1, 26 | } 27 | } 28 | 29 | func (tx *Tx) Update(table string) *UpdateBuilder { 30 | return &UpdateBuilder{ 31 | runner: tx, 32 | EventReceiver: tx, 33 | Dialect: tx.Dialect, 34 | UpdateStmt: Update(table), 35 | LimitCount: -1, 36 | } 37 | } 38 | 39 | func (sess *Session) UpdateBySql(query string, value ...interface{}) *UpdateBuilder { 40 | return &UpdateBuilder{ 41 | runner: sess, 42 | EventReceiver: sess, 43 | Dialect: sess.Dialect, 44 | UpdateStmt: UpdateBySql(query, value...), 45 | LimitCount: -1, 46 | } 47 | } 48 | 49 | func (tx *Tx) UpdateBySql(query string, value ...interface{}) *UpdateBuilder { 50 | return &UpdateBuilder{ 51 | runner: tx, 52 | EventReceiver: tx, 53 | Dialect: tx.Dialect, 54 | UpdateStmt: UpdateBySql(query, value...), 55 | LimitCount: -1, 56 | } 57 | } 58 | 59 | func (b *UpdateBuilder) Exec() (sql.Result, error) { 60 | return b.ExecContext(context.Background()) 61 | } 62 | 63 | func (b *UpdateBuilder) ExecContext(ctx context.Context) (sql.Result, error) { 64 | return exec(ctx, b.runner, b.EventReceiver, b, b.Dialect) 65 | } 66 | 67 | func (b *UpdateBuilder) Set(column string, value interface{}) *UpdateBuilder { 68 | b.UpdateStmt.Set(column, value) 69 | return b 70 | } 71 | 72 | func (b *UpdateBuilder) SetMap(m map[string]interface{}) *UpdateBuilder { 73 | b.UpdateStmt.SetMap(m) 74 | return b 75 | } 76 | 77 | func (b *UpdateBuilder) Where(query interface{}, value ...interface{}) *UpdateBuilder { 78 | b.UpdateStmt.Where(query, value...) 79 | return b 80 | } 81 | 82 | func (b *UpdateBuilder) Limit(n uint64) *UpdateBuilder { 83 | b.LimitCount = int64(n) 84 | return b 85 | } 86 | 87 | func (b *UpdateBuilder) Build(d Dialect, buf Buffer) error { 88 | err := b.UpdateStmt.Build(b.Dialect, buf) 89 | if err != nil { 90 | return err 91 | } 92 | if b.LimitCount >= 0 { 93 | buf.WriteString(" LIMIT ") 94 | buf.WriteString(fmt.Sprint(b.LimitCount)) 95 | } 96 | return nil 97 | } 98 | -------------------------------------------------------------------------------- /vendor/github.com/gocraft/dbr/util.go: -------------------------------------------------------------------------------- 1 | package dbr 2 | 3 | import ( 4 | "bytes" 5 | "database/sql/driver" 6 | "reflect" 7 | "unicode" 8 | ) 9 | 10 | func camelCaseToSnakeCase(name string) string { 11 | buf := new(bytes.Buffer) 12 | 13 | runes := []rune(name) 14 | 15 | for i := 0; i < len(runes); i++ { 16 | buf.WriteRune(unicode.ToLower(runes[i])) 17 | if i != len(runes)-1 && unicode.IsUpper(runes[i+1]) && 18 | (unicode.IsLower(runes[i]) || unicode.IsDigit(runes[i]) || 19 | (i != len(runes)-2 && unicode.IsLower(runes[i+2]))) { 20 | buf.WriteRune('_') 21 | } 22 | } 23 | 24 | return buf.String() 25 | } 26 | 27 | func structMap(value reflect.Value) map[string]reflect.Value { 28 | m := make(map[string]reflect.Value) 29 | structValue(m, value) 30 | return m 31 | } 32 | 33 | var ( 34 | typeValuer = reflect.TypeOf((*driver.Valuer)(nil)).Elem() 35 | ) 36 | 37 | func structValue(m map[string]reflect.Value, value reflect.Value) { 38 | if value.Type().Implements(typeValuer) { 39 | return 40 | } 41 | switch value.Kind() { 42 | case reflect.Ptr: 43 | if value.IsNil() { 44 | return 45 | } 46 | structValue(m, value.Elem()) 47 | case reflect.Struct: 48 | t := value.Type() 49 | for i := 0; i < t.NumField(); i++ { 50 | field := t.Field(i) 51 | if field.PkgPath != "" && !field.Anonymous { 52 | // unexported 53 | continue 54 | } 55 | tag := field.Tag.Get("db") 56 | if tag == "-" { 57 | // ignore 58 | continue 59 | } 60 | if tag == "" { 61 | // no tag, but we can record the field name 62 | tag = camelCaseToSnakeCase(field.Name) 63 | } 64 | fieldValue := value.Field(i) 65 | if _, ok := m[tag]; !ok { 66 | m[tag] = fieldValue 67 | } 68 | structValue(m, fieldValue) 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /vendor/github.com/golang/example/stringutil/reverse.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Google Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package stringutil contains utility functions for working with strings. 18 | package stringutil 19 | 20 | // Reverse returns its argument string reversed rune-wise left to right. 21 | func Reverse(s string) string { 22 | r := []rune(s) 23 | for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 { 24 | r[i], r[j] = r[j], r[i] 25 | } 26 | return string(r) 27 | } 28 | -------------------------------------------------------------------------------- /vendor/github.com/golang/glog/README: -------------------------------------------------------------------------------- 1 | glog 2 | ==== 3 | 4 | Leveled execution logs for Go. 5 | 6 | This is an efficient pure Go implementation of leveled logs in the 7 | manner of the open source C++ package 8 | https://github.com/google/glog 9 | 10 | By binding methods to booleans it is possible to use the log package 11 | without paying the expense of evaluating the arguments to the log. 12 | Through the -vmodule flag, the package also provides fine-grained 13 | control over logging at the file level. 14 | 15 | The comment from glog.go introduces the ideas: 16 | 17 | Package glog implements logging analogous to the Google-internal 18 | C++ INFO/ERROR/V setup. It provides functions Info, Warning, 19 | Error, Fatal, plus formatting variants such as Infof. It 20 | also provides V-style logging controlled by the -v and 21 | -vmodule=file=2 flags. 22 | 23 | Basic examples: 24 | 25 | glog.Info("Prepare to repel boarders") 26 | 27 | glog.Fatalf("Initialization failed: %s", err) 28 | 29 | See the documentation for the V function for an explanation 30 | of these examples: 31 | 32 | if glog.V(2) { 33 | glog.Info("Starting transaction...") 34 | } 35 | 36 | glog.V(2).Infoln("Processed", nItems, "elements") 37 | 38 | 39 | The repository contains an open source version of the log package 40 | used inside Google. The master copy of the source lives inside 41 | Google, not here. The code in this repo is for export only and is not itself 42 | under development. Feature requests will be ignored. 43 | 44 | Send bug reports to golang-nuts@googlegroups.com. 45 | -------------------------------------------------------------------------------- /vendor/github.com/google/go-querystring/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Google. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/github.com/koding/multiconfig/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | 25 | *~ 26 | -------------------------------------------------------------------------------- /vendor/github.com/koding/multiconfig/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go: 1.3 3 | script: go test ./... 4 | 5 | -------------------------------------------------------------------------------- /vendor/github.com/koding/multiconfig/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Koding, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /vendor/github.com/koding/multiconfig/doc.go: -------------------------------------------------------------------------------- 1 | // Package multiconfig provides a way to load and read configurations from 2 | // multiple sources. You can read from TOML file, JSON file, YAML file, Environment 3 | // Variables and flags. You can set the order of reader with MultiLoader. Package 4 | // is extensible, you can add your custom Loader by implementing the Load interface. 5 | package multiconfig 6 | -------------------------------------------------------------------------------- /vendor/github.com/koding/multiconfig/multiloader.go: -------------------------------------------------------------------------------- 1 | package multiconfig 2 | 3 | type multiLoader []Loader 4 | 5 | // MultiLoader creates a loader that executes the loaders one by one in order 6 | // and returns on the first error. 7 | func MultiLoader(loader ...Loader) Loader { 8 | return multiLoader(loader) 9 | } 10 | 11 | // Load loads the source into the config defined by struct s 12 | func (m multiLoader) Load(s interface{}) error { 13 | for _, loader := range m { 14 | if err := loader.Load(s); err != nil { 15 | return err 16 | } 17 | } 18 | 19 | return nil 20 | } 21 | 22 | // MustLoad loads the source into the struct, it panics if gets any error 23 | func (m multiLoader) MustLoad(s interface{}) { 24 | if err := m.Load(s); err != nil { 25 | panic(err) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /vendor/github.com/koding/multiconfig/multivalidator.go: -------------------------------------------------------------------------------- 1 | package multiconfig 2 | 3 | type multiValidator []Validator 4 | 5 | // MultiValidator accepts variadic validators and satisfies Validator interface. 6 | func MultiValidator(validators ...Validator) Validator { 7 | return multiValidator(validators) 8 | } 9 | 10 | // Validate tries to validate given struct with all the validators. If it doesn't 11 | // have any Validator it will simply skip the validation step. If any of the 12 | // given validators return err, it will stop validating and return it. 13 | func (d multiValidator) Validate(s interface{}) error { 14 | for _, validator := range d { 15 | if err := validator.Validate(s); err != nil { 16 | return err 17 | } 18 | } 19 | 20 | return nil 21 | } 22 | 23 | // MustValidate validates the struct, it panics if gets any error 24 | func (d multiValidator) MustValidate(s interface{}) { 25 | if err := d.Validate(s); err != nil { 26 | panic(err) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /vendor/github.com/koding/multiconfig/tag.go: -------------------------------------------------------------------------------- 1 | package multiconfig 2 | 3 | import ( 4 | "reflect" 5 | 6 | "github.com/fatih/structs" 7 | ) 8 | 9 | // TagLoader satisfies the loader interface. It parses a struct's field tags 10 | // and populates the each field with that given tag. 11 | type TagLoader struct { 12 | // DefaultTagName is the default tag name for struct fields to define 13 | // default values for a field. Example: 14 | // 15 | // // Field's default value is "koding". 16 | // Name string `default:"koding"` 17 | // 18 | // The default value is "default" if it's not set explicitly. 19 | DefaultTagName string 20 | } 21 | 22 | func (t *TagLoader) Load(s interface{}) error { 23 | if t.DefaultTagName == "" { 24 | t.DefaultTagName = "default" 25 | } 26 | 27 | for _, field := range structs.Fields(s) { 28 | 29 | if err := t.processField(t.DefaultTagName, field); err != nil { 30 | return err 31 | } 32 | } 33 | 34 | return nil 35 | } 36 | 37 | // processField gets tagName and the field, recursively checks if the field has the given 38 | // tag, if yes, sets it otherwise ignores 39 | func (t *TagLoader) processField(tagName string, field *structs.Field) error { 40 | switch field.Kind() { 41 | case reflect.Struct: 42 | for _, f := range field.Fields() { 43 | if err := t.processField(tagName, f); err != nil { 44 | return err 45 | } 46 | } 47 | default: 48 | defaultVal := field.Tag(t.DefaultTagName) 49 | if defaultVal == "" { 50 | return nil 51 | } 52 | 53 | err := fieldSet(field, defaultVal) 54 | if err != nil { 55 | return err 56 | } 57 | } 58 | 59 | return nil 60 | } 61 | -------------------------------------------------------------------------------- /vendor/github.com/koding/multiconfig/validator.go: -------------------------------------------------------------------------------- 1 | package multiconfig 2 | 3 | import ( 4 | "fmt" 5 | "reflect" 6 | 7 | "github.com/fatih/structs" 8 | ) 9 | 10 | // Validator validates the config against any predefined rules, those predefined 11 | // rules should be given to this package. The implementer will be responsible 12 | // for the logic. 13 | type Validator interface { 14 | // Validate validates the config struct 15 | Validate(s interface{}) error 16 | } 17 | 18 | // RequiredValidator validates the struct against zero values. 19 | type RequiredValidator struct { 20 | // TagName holds the validator tag name. The default is "required" 21 | TagName string 22 | 23 | // TagValue holds the expected value of the validator. The default is "true" 24 | TagValue string 25 | } 26 | 27 | // Validate validates the given struct agaist field's zero values. If 28 | // intentionaly, the value of a field is `zero-valued`(e.g false, 0, "") 29 | // required tag should not be set for that field. 30 | func (e *RequiredValidator) Validate(s interface{}) error { 31 | if e.TagName == "" { 32 | e.TagName = "required" 33 | } 34 | 35 | if e.TagValue == "" { 36 | e.TagValue = "true" 37 | } 38 | 39 | for _, field := range structs.Fields(s) { 40 | if err := e.processField("", field); err != nil { 41 | return err 42 | } 43 | } 44 | 45 | return nil 46 | } 47 | 48 | func (e *RequiredValidator) processField(fieldName string, field *structs.Field) error { 49 | fieldName += field.Name() 50 | switch field.Kind() { 51 | case reflect.Struct: 52 | // this is used for error messages below, when we have an error at the 53 | // child properties add parent properties into the error message as well 54 | fieldName += "." 55 | 56 | for _, f := range field.Fields() { 57 | if err := e.processField(fieldName, f); err != nil { 58 | return err 59 | } 60 | } 61 | default: 62 | val := field.Tag(e.TagName) 63 | if val != e.TagValue { 64 | return nil 65 | } 66 | 67 | if field.IsZero() { 68 | return fmt.Errorf("multiconfig: field '%s' is required", fieldName) 69 | } 70 | } 71 | 72 | return nil 73 | } 74 | -------------------------------------------------------------------------------- /vendor/github.com/kubesphere/sonargo/sonar/duplications_service.go: -------------------------------------------------------------------------------- 1 | // Get duplication information for a project. 2 | package sonargo 3 | 4 | import "net/http" 5 | 6 | type DuplicationsService struct { 7 | client *Client 8 | } 9 | 10 | type DuplicationsShowObject struct { 11 | Duplications []*Duplication `json:"duplications,omitempty"` 12 | Files *Files `json:"files,omitempty"` 13 | } 14 | 15 | type Block struct { 16 | Ref string `json:"_ref,omitempty"` 17 | From int64 `json:"from,omitempty"` 18 | Size int64 `json:"size,omitempty"` 19 | } 20 | 21 | type Duplication struct { 22 | Blocks []*Block `json:"blocks,omitempty"` 23 | } 24 | 25 | type Files struct { 26 | One *File `json:"1,omitempty"` 27 | Two *File `json:"2,omitempty"` 28 | Three *File `json:"3,omitempty"` 29 | } 30 | 31 | type File struct { 32 | Key string `json:"key,omitempty"` 33 | Name string `json:"name,omitempty"` 34 | ProjectName string `json:"projectName,omitempty"` 35 | } 36 | 37 | type DuplicationsShowOption struct { 38 | Key string `url:"key,omitempty"` // Description:"File key",ExampleValue:"my_project:/src/foo/Bar.php" 39 | Uuid string `url:"uuid,omitempty"` // Description:"File ID. If provided, 'key' must not be provided.",ExampleValue:"584a89f2-8037-4f7b-b82c-8b45d2d63fb2" 40 | } 41 | 42 | // Show Get duplications. Require Browse permission on file's project 43 | func (s *DuplicationsService) Show(opt *DuplicationsShowOption) (v *DuplicationsShowObject, resp *http.Response, err error) { 44 | err = s.ValidateShowOpt(opt) 45 | if err != nil { 46 | return 47 | } 48 | req, err := s.client.NewRequest("GET", "duplications/show", opt) 49 | if err != nil { 50 | return 51 | } 52 | v = new(DuplicationsShowObject) 53 | resp, err = s.client.Do(req, v) 54 | if err != nil { 55 | return nil, resp, err 56 | } 57 | return 58 | } 59 | -------------------------------------------------------------------------------- /vendor/github.com/kubesphere/sonargo/sonar/languages_service.go: -------------------------------------------------------------------------------- 1 | // Get the list of programming languages supported in this instance. 2 | package sonargo 3 | 4 | import "net/http" 5 | 6 | type LanguagesService struct { 7 | client *Client 8 | } 9 | 10 | type LanguagesListObject struct { 11 | Languages []*Language `json:"languages,omitempty"` 12 | } 13 | 14 | type Language struct { 15 | Key string `json:"key,omitempty"` 16 | Name string `json:"name,omitempty"` 17 | } 18 | 19 | type LanguagesListOption struct { 20 | Ps int `url:"ps,omitempty"` // Description:"The size of the list to return, 0 for all languages",ExampleValue:"25" 21 | Q string `url:"q,omitempty"` // Description:"A pattern to match language keys/names against",ExampleValue:"java" 22 | } 23 | 24 | // List List supported programming languages 25 | func (s *LanguagesService) List(opt *LanguagesListOption) (v *LanguagesListObject, resp *http.Response, err error) { 26 | err = s.ValidateListOpt(opt) 27 | if err != nil { 28 | return 29 | } 30 | req, err := s.client.NewRequest("GET", "languages/list", opt) 31 | if err != nil { 32 | return 33 | } 34 | v = new(LanguagesListObject) 35 | resp, err = s.client.Do(req, v) 36 | if err != nil { 37 | return nil, resp, err 38 | } 39 | return 40 | } 41 | -------------------------------------------------------------------------------- /vendor/github.com/kubesphere/sonargo/sonar/project_badges_service.go: -------------------------------------------------------------------------------- 1 | // Generate badges based on quality gates or measures 2 | package sonargo 3 | 4 | import "net/http" 5 | 6 | type ProjectBadgesService struct { 7 | client *Client 8 | } 9 | 10 | type ProjectBadgesMeasureOption struct { 11 | Branch string `url:"branch,omitempty"` // Description:"Branch key",ExampleValue:"feature/my_branch" 12 | Metric string `url:"metric,omitempty"` // Description:"Metric key",ExampleValue:"" 13 | Project string `url:"project,omitempty"` // Description:"Project key",ExampleValue:"my_project" 14 | PullRequest string `url:"pullRequest,omitempty"` // Description:"Pull request id",ExampleValue:"5461" 15 | } 16 | 17 | // Measure Generate badge for project's measure as an SVG.
Requires 'Browse' permission on the specified project. 18 | func (s *ProjectBadgesService) Measure(opt *ProjectBadgesMeasureOption) (v *string, resp *http.Response, err error) { 19 | err = s.ValidateMeasureOpt(opt) 20 | if err != nil { 21 | return 22 | } 23 | req, err := s.client.NewRequest("GET", "project_badges/measure", opt) 24 | if err != nil { 25 | return 26 | } 27 | v = new(string) 28 | resp, err = s.client.Do(req, v) 29 | if err != nil { 30 | return nil, resp, err 31 | } 32 | return 33 | } 34 | 35 | type ProjectBadgesQualityGateOption struct { 36 | Branch string `url:"branch,omitempty"` // Description:"Branch key",ExampleValue:"feature/my_branch" 37 | Project string `url:"project,omitempty"` // Description:"Project key",ExampleValue:"my_project" 38 | PullRequest string `url:"pullRequest,omitempty"` // Description:"Pull request id",ExampleValue:"5461" 39 | } 40 | 41 | // QualityGate Generate badge for project's quality gate as an SVG.
Requires 'Browse' permission on the specified project. 42 | func (s *ProjectBadgesService) QualityGate(opt *ProjectBadgesQualityGateOption) (v *string, resp *http.Response, err error) { 43 | err = s.ValidateQualityGateOpt(opt) 44 | if err != nil { 45 | return 46 | } 47 | req, err := s.client.NewRequest("GET", "project_badges/quality_gate", opt) 48 | if err != nil { 49 | return 50 | } 51 | v = new(string) 52 | resp, err = s.client.Do(req, v) 53 | if err != nil { 54 | return nil, resp, err 55 | } 56 | return 57 | } 58 | -------------------------------------------------------------------------------- /vendor/github.com/kubesphere/sonargo/sonar/project_pull_requests_service.go: -------------------------------------------------------------------------------- 1 | // Manage pull request (only available when the Branch plugin is installed) 2 | package sonargo 3 | 4 | import "net/http" 5 | 6 | type ProjectPullRequestsService struct { 7 | client *Client 8 | } 9 | 10 | type ProjectPullRequestsListObject struct { 11 | PullRequests []*PullRequest `json:"pullRequests,omitempty"` 12 | } 13 | 14 | type PullRequest struct { 15 | AnalysisDate string `json:"analysisDate,omitempty"` 16 | Base string `json:"base,omitempty"` 17 | Branch string `json:"branch,omitempty"` 18 | Key string `json:"key,omitempty"` 19 | Status Status `json:"status,omitempty"` 20 | Title string `json:"title,omitempty"` 21 | URL string `json:"url,omitempty"` 22 | } 23 | 24 | type ProjectPullRequestsDeleteOption struct { 25 | Project string `url:"project,omitempty"` // Description:"Project key",ExampleValue:"my_project" 26 | PullRequest int `url:"pullRequest,omitempty"` // Description:"Pull request id",ExampleValue:"1543" 27 | } 28 | 29 | // Delete Delete a pull request.
Requires 'Administer' rights on the specified project. 30 | func (s *ProjectPullRequestsService) Delete(opt *ProjectPullRequestsDeleteOption) (resp *http.Response, err error) { 31 | err = s.ValidateDeleteOpt(opt) 32 | if err != nil { 33 | return 34 | } 35 | req, err := s.client.NewRequest("POST", "project_pull_requests/delete", opt) 36 | if err != nil { 37 | return 38 | } 39 | resp, err = s.client.Do(req, nil) 40 | if err != nil { 41 | return 42 | } 43 | return 44 | } 45 | 46 | type ProjectPullRequestsListOption struct { 47 | Project string `url:"project,omitempty"` // Description:"Project key",ExampleValue:"my_project" 48 | } 49 | 50 | // List List the pull requests of a project.
One of the following permissions is required:
  • 'Browse' rights on the specified project
  • 'Execute Analysis' rights on the specified project
51 | func (s *ProjectPullRequestsService) List(opt *ProjectPullRequestsListOption) (v *ProjectPullRequestsListObject, resp *http.Response, err error) { 52 | err = s.ValidateListOpt(opt) 53 | if err != nil { 54 | return 55 | } 56 | req, err := s.client.NewRequest("GET", "project_pull_requests/list", opt) 57 | if err != nil { 58 | return 59 | } 60 | v = new(ProjectPullRequestsListObject) 61 | resp, err = s.client.Do(req, v) 62 | if err != nil { 63 | return nil, resp, err 64 | } 65 | return 66 | } 67 | -------------------------------------------------------------------------------- /vendor/github.com/kubesphere/sonargo/sonar/project_tags_service.go: -------------------------------------------------------------------------------- 1 | // Manage project tags 2 | package sonargo 3 | 4 | import "net/http" 5 | 6 | type ProjectTagsService struct { 7 | client *Client 8 | } 9 | 10 | type ProjectTagsSearchOption struct { 11 | Ps int `url:"ps,omitempty"` // Description:"Page size. Must be greater than 0 and less or equal than 100",ExampleValue:"20" 12 | Q string `url:"q,omitempty"` // Description:"Limit search to tags that contain the supplied string.",ExampleValue:"off" 13 | } 14 | 15 | // Search Search tags 16 | func (s *ProjectTagsService) Search(opt *ProjectTagsSearchOption) (v *IssuesTagsObject, resp *http.Response, err error) { 17 | err = s.ValidateSearchOpt(opt) 18 | if err != nil { 19 | return 20 | } 21 | req, err := s.client.NewRequest("GET", "project_tags/search", opt) 22 | if err != nil { 23 | return 24 | } 25 | v = new(IssuesTagsObject) 26 | resp, err = s.client.Do(req, v) 27 | if err != nil { 28 | return nil, resp, err 29 | } 30 | return 31 | } 32 | 33 | type ProjectTagsSetOption struct { 34 | Project string `url:"project,omitempty"` // Description:"Project key",ExampleValue:"my_project" 35 | Tags *string `url:"tags,omitempty"` // Description:"Comma-separated list of tags",ExampleValue:"finance, offshore" 36 | } 37 | 38 | // Set Set tags on a project.
Requires the following permission: 'Administer' rights on the specified project 39 | func (s *ProjectTagsService) Set(opt *ProjectTagsSetOption) (resp *http.Response, err error) { 40 | err = s.ValidateSetOpt(opt) 41 | if err != nil { 42 | return 43 | } 44 | req, err := s.client.NewRequest("POST", "project_tags/set", opt) 45 | if err != nil { 46 | return 47 | } 48 | resp, err = s.client.Do(req, nil) 49 | if err != nil { 50 | return 51 | } 52 | return 53 | } 54 | -------------------------------------------------------------------------------- /vendor/github.com/kubesphere/sonargo/sonar/server_service.go: -------------------------------------------------------------------------------- 1 | // 2 | package sonargo 3 | 4 | import "net/http" 5 | 6 | type ServerService struct { 7 | client *Client 8 | } 9 | 10 | // Version Version of SonarQube in plain text 11 | func (s *ServerService) Version() (v *string, resp *http.Response, err error) { 12 | req, err := s.client.NewRequest("GET", "server/version", nil) 13 | if err != nil { 14 | return 15 | } 16 | v = new(string) 17 | resp, err = s.client.Do(req, v) 18 | if err != nil { 19 | return nil, resp, err 20 | } 21 | return 22 | } 23 | -------------------------------------------------------------------------------- /vendor/github.com/mitchellh/mapstructure/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.9.x 5 | - tip 6 | 7 | script: 8 | - go test 9 | -------------------------------------------------------------------------------- /vendor/github.com/mitchellh/mapstructure/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Mitchell Hashimoto 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /vendor/github.com/mitchellh/mapstructure/README.md: -------------------------------------------------------------------------------- 1 | # mapstructure [![Godoc](https://godoc.org/github.com/mitchellh/mapstructure?status.svg)](https://godoc.org/github.com/mitchellh/mapstructure) 2 | 3 | mapstructure is a Go library for decoding generic map values to structures 4 | and vice versa, while providing helpful error handling. 5 | 6 | This library is most useful when decoding values from some data stream (JSON, 7 | Gob, etc.) where you don't _quite_ know the structure of the underlying data 8 | until you read a part of it. You can therefore read a `map[string]interface{}` 9 | and use this library to decode it into the proper underlying native Go 10 | structure. 11 | 12 | ## Installation 13 | 14 | Standard `go get`: 15 | 16 | ``` 17 | $ go get github.com/mitchellh/mapstructure 18 | ``` 19 | 20 | ## Usage & Example 21 | 22 | For usage and examples see the [Godoc](http://godoc.org/github.com/mitchellh/mapstructure). 23 | 24 | The `Decode` function has examples associated with it there. 25 | 26 | ## But Why?! 27 | 28 | Go offers fantastic standard libraries for decoding formats such as JSON. 29 | The standard method is to have a struct pre-created, and populate that struct 30 | from the bytes of the encoded format. This is great, but the problem is if 31 | you have configuration or an encoding that changes slightly depending on 32 | specific fields. For example, consider this JSON: 33 | 34 | ```json 35 | { 36 | "type": "person", 37 | "name": "Mitchell" 38 | } 39 | ``` 40 | 41 | Perhaps we can't populate a specific structure without first reading 42 | the "type" field from the JSON. We could always do two passes over the 43 | decoding of the JSON (reading the "type" first, and the rest later). 44 | However, it is much simpler to just decode this into a `map[string]interface{}` 45 | structure, read the "type" key, then use something like this library 46 | to decode it into the proper structure. 47 | -------------------------------------------------------------------------------- /vendor/github.com/mitchellh/mapstructure/error.go: -------------------------------------------------------------------------------- 1 | package mapstructure 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | "sort" 7 | "strings" 8 | ) 9 | 10 | // Error implements the error interface and can represents multiple 11 | // errors that occur in the course of a single decode. 12 | type Error struct { 13 | Errors []string 14 | } 15 | 16 | func (e *Error) Error() string { 17 | points := make([]string, len(e.Errors)) 18 | for i, err := range e.Errors { 19 | points[i] = fmt.Sprintf("* %s", err) 20 | } 21 | 22 | sort.Strings(points) 23 | return fmt.Sprintf( 24 | "%d error(s) decoding:\n\n%s", 25 | len(e.Errors), strings.Join(points, "\n")) 26 | } 27 | 28 | // WrappedErrors implements the errwrap.Wrapper interface to make this 29 | // return value more useful with the errwrap and go-multierror libraries. 30 | func (e *Error) WrappedErrors() []error { 31 | if e == nil { 32 | return nil 33 | } 34 | 35 | result := make([]error, len(e.Errors)) 36 | for i, e := range e.Errors { 37 | result[i] = errors.New(e) 38 | } 39 | 40 | return result 41 | } 42 | 43 | func appendErrors(errors []string, err error) []string { 44 | switch e := err.(type) { 45 | case *Error: 46 | return append(errors, e.Errors...) 47 | default: 48 | return append(errors, e.Error()) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /vendor/github.com/mitchellh/mapstructure/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/mitchellh/mapstructure 2 | -------------------------------------------------------------------------------- /vendor/github.com/pmezard/go-difflib/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, Patrick Mezard 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | The names of its contributors may not be used to endorse or promote 14 | products derived from this software without specific prior written 15 | permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 18 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 19 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 20 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 23 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 24 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/github.com/sony/sonyflake/.gitignore: -------------------------------------------------------------------------------- 1 | example/sonyflake_server 2 | -------------------------------------------------------------------------------- /vendor/github.com/sony/sonyflake/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go: 3 | - 1.5 4 | - 1.6 5 | sudo: false 6 | before_install: 7 | - go get -u github.com/golang/lint/golint 8 | - go get github.com/axw/gocov/gocov 9 | - go get github.com/mattn/goveralls 10 | script: 11 | - test -z "`gofmt -l .`" 12 | - test -z "`golint ./...`" 13 | - $GOPATH/bin/goveralls -service=travis-ci 14 | - cd example && ./linux64_build.sh 15 | -------------------------------------------------------------------------------- /vendor/github.com/sony/sonyflake/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright 2015 Sony Corporation 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /vendor/github.com/speps/go-hashids/.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | indent_size = 4 -------------------------------------------------------------------------------- /vendor/github.com/speps/go-hashids/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | -------------------------------------------------------------------------------- /vendor/github.com/speps/go-hashids/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Remi Gillig 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /vendor/github.com/speps/go-hashids/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | go-hashids [![Build Status](https://ci.appveyor.com/api/projects/status/1s8yeafycpa2vdaq?svg=true)](https://ci.appveyor.com/project/speps/go-hashids) [![GoDoc](https://godoc.org/github.com/speps/go-hashids?status.svg)](https://godoc.org/github.com/speps/go-hashids) 4 | ========== 5 | 6 | Go (golang) v1 implementation of http://www.hashids.org 7 | under MIT License (same as the original implementations) 8 | 9 | Original implementations by [Ivan Akimov](https://github.com/ivanakimov) 10 | 11 | ### Setup 12 |
go get github.com/speps/go-hashids
13 | 14 | CLI tool : 15 | 16 |
go get github.com/speps/go-hashids/cmd/hashid
17 | 18 | ### Example 19 | ```go 20 | package main 21 | 22 | import "fmt" 23 | import "github.com/speps/go-hashids" 24 | 25 | func main() { 26 | hd := hashids.NewData() 27 | hd.Salt = "this is my salt" 28 | hd.MinLength = 30 29 | h, _ := hashids.NewWithData(hd) 30 | e, _ := h.Encode([]int{45, 434, 1313, 99}) 31 | fmt.Println(e) 32 | d, _ := h.DecodeWithError(e) 33 | fmt.Println(d) 34 | } 35 | ``` 36 | 37 | ### Thanks to all the contributors 38 | 39 | * [Harm Aarts](https://github.com/haarts) 40 | * [Christoffer G. Thomsen](https://github.com/cgt) 41 | * [Peter Hellberg](https://github.com/peterhellberg) 42 | * [Rémy Oudompheng](https://github.com/remyoudompheng) 43 | * [Mart Roosmaa](https://github.com/roosmaa) 44 | * [Jakub Kramarz](https://github.com/jkramarz) 45 | * [Zou Xifeng](https://github.com/zouxifeng) 46 | * [Per Persson](https://github.com/md2perpe) 47 | * [Baiju Muthukadan](https://github.com/baijum) 48 | * [Pablo de la Concepción Sanz](https://github.com/pconcepcion) 49 | * [Olivier Mengué](https://github.com/dolmen) 50 | * [Matthew Valimaki](https://github.com/matthewvalimaki) 51 | * [Cody Maloney](https://github.com/cmaloney) 52 | 53 | Let me know if I forgot anyone of course. 54 | 55 | ### Changelog 56 | 57 | 2017/05/09 58 | 59 | * Changed API 60 | * `New` methods now return errors 61 | * Added sanity check in `Decode` that makes sure that the salt is consistent 62 | 63 | 2014/09/13 64 | 65 | * Updated to Hashids v1.0.0 (should be compatible with other implementations, let me know if not, was checked against the Javascript version) 66 | * Changed API 67 | * Encrypt/Decrypt are now Encode/Decode 68 | * HashID is now constructed from HashIDData containing alphabet, salt and minimum length 69 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 - 2013 Mat Ryer and Tyler Bunnell 2 | 3 | Please consider promoting this project if you find it useful. 4 | 5 | Permission is hereby granted, free of charge, to any person 6 | obtaining a copy of this software and associated documentation 7 | files (the "Software"), to deal in the Software without restriction, 8 | including without limitation the rights to use, copy, modify, merge, 9 | publish, distribute, sublicense, and/or sell copies of the Software, 10 | and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 20 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT 21 | OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 22 | OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/assertion_format.go.tmpl: -------------------------------------------------------------------------------- 1 | {{.CommentFormat}} 2 | func {{.DocInfo.Name}}f(t TestingT, {{.ParamsFormat}}) bool { 3 | if h, ok := t.(tHelper); ok { h.Helper() } 4 | return {{.DocInfo.Name}}(t, {{.ForwardedParamsFormat}}) 5 | } 6 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/assertion_forward.go.tmpl: -------------------------------------------------------------------------------- 1 | {{.CommentWithoutT "a"}} 2 | func (a *Assertions) {{.DocInfo.Name}}({{.Params}}) bool { 3 | if h, ok := a.t.(tHelper); ok { h.Helper() } 4 | return {{.DocInfo.Name}}(a.t, {{.ForwardedParams}}) 5 | } 6 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/doc.go: -------------------------------------------------------------------------------- 1 | // Package assert provides a set of comprehensive testing tools for use with the normal Go testing system. 2 | // 3 | // Example Usage 4 | // 5 | // The following is a complete example using assert in a standard test function: 6 | // import ( 7 | // "testing" 8 | // "github.com/stretchr/testify/assert" 9 | // ) 10 | // 11 | // func TestSomething(t *testing.T) { 12 | // 13 | // var a string = "Hello" 14 | // var b string = "Hello" 15 | // 16 | // assert.Equal(t, a, b, "The two words should be the same.") 17 | // 18 | // } 19 | // 20 | // if you assert many times, use the format below: 21 | // 22 | // import ( 23 | // "testing" 24 | // "github.com/stretchr/testify/assert" 25 | // ) 26 | // 27 | // func TestSomething(t *testing.T) { 28 | // assert := assert.New(t) 29 | // 30 | // var a string = "Hello" 31 | // var b string = "Hello" 32 | // 33 | // assert.Equal(a, b, "The two words should be the same.") 34 | // } 35 | // 36 | // Assertions 37 | // 38 | // Assertions allow you to easily write test code, and are global funcs in the `assert` package. 39 | // All assertion functions take, as the first argument, the `*testing.T` object provided by the 40 | // testing framework. This allows the assertion funcs to write the failings and other details to 41 | // the correct place. 42 | // 43 | // Every assertion function also takes an optional string message as the final argument, 44 | // allowing custom error messages to be appended to the message the assertion method outputs. 45 | package assert 46 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/errors.go: -------------------------------------------------------------------------------- 1 | package assert 2 | 3 | import ( 4 | "errors" 5 | ) 6 | 7 | // AnError is an error instance useful for testing. If the code does not care 8 | // about error specifics, and only needs to return the error for example, this 9 | // error should be used to make the test code more readable. 10 | var AnError = errors.New("assert.AnError general error for testing") 11 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/forward_assertions.go: -------------------------------------------------------------------------------- 1 | package assert 2 | 3 | // Assertions provides assertion methods around the 4 | // TestingT interface. 5 | type Assertions struct { 6 | t TestingT 7 | } 8 | 9 | // New makes a new Assertions object for the specified TestingT. 10 | func New(t TestingT) *Assertions { 11 | return &Assertions{ 12 | t: t, 13 | } 14 | } 15 | 16 | //go:generate go run ../_codegen/main.go -output-package=assert -template=assertion_forward.go.tmpl -include-format-funcs 17 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/AUTHORS: -------------------------------------------------------------------------------- 1 | # This source code refers to The Go Authors for copyright purposes. 2 | # The master list of authors is in the main Go distribution, 3 | # visible at http://tip.golang.org/AUTHORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This source code was written by the Go contributors. 2 | # The master list of contributors is in the main Go distribution, 3 | # visible at http://tip.golang.org/CONTRIBUTORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/html/atom/atom.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package atom provides integer codes (also known as atoms) for a fixed set of 6 | // frequently occurring HTML strings: tag names and attribute keys such as "p" 7 | // and "id". 8 | // 9 | // Sharing an atom's name between all elements with the same tag can result in 10 | // fewer string allocations when tokenizing and parsing HTML. Integer 11 | // comparisons are also generally faster than string comparisons. 12 | // 13 | // The value of an atom's particular code is not guaranteed to stay the same 14 | // between versions of this package. Neither is any ordering guaranteed: 15 | // whether atom.H1 < atom.H2 may also change. The codes are not guaranteed to 16 | // be dense. The only guarantees are that e.g. looking up "div" will yield 17 | // atom.Div, calling atom.Div.String will return "div", and atom.Div != 0. 18 | package atom // import "golang.org/x/net/html/atom" 19 | 20 | // Atom is an integer code for a string. The zero value maps to "". 21 | type Atom uint32 22 | 23 | // String returns the atom's name. 24 | func (a Atom) String() string { 25 | start := uint32(a >> 8) 26 | n := uint32(a & 0xff) 27 | if start+n > uint32(len(atomText)) { 28 | return "" 29 | } 30 | return atomText[start : start+n] 31 | } 32 | 33 | func (a Atom) string() string { 34 | return atomText[a>>8 : a>>8+a&0xff] 35 | } 36 | 37 | // fnv computes the FNV hash with an arbitrary starting value h. 38 | func fnv(h uint32, s []byte) uint32 { 39 | for i := range s { 40 | h ^= uint32(s[i]) 41 | h *= 16777619 42 | } 43 | return h 44 | } 45 | 46 | func match(s string, t []byte) bool { 47 | for i, c := range t { 48 | if s[i] != c { 49 | return false 50 | } 51 | } 52 | return true 53 | } 54 | 55 | // Lookup returns the atom whose name is s. It returns zero if there is no 56 | // such atom. The lookup is case sensitive. 57 | func Lookup(s []byte) Atom { 58 | if len(s) == 0 || len(s) > maxAtomLen { 59 | return 0 60 | } 61 | h := fnv(hash0, s) 62 | if a := table[h&uint32(len(table)-1)]; int(a&0xff) == len(s) && match(a.string(), s) { 63 | return a 64 | } 65 | if a := table[(h>>16)&uint32(len(table)-1)]; int(a&0xff) == len(s) && match(a.string(), s) { 66 | return a 67 | } 68 | return 0 69 | } 70 | 71 | // String returns a string whose contents are equal to s. In that sense, it is 72 | // equivalent to string(s) but may be more efficient. 73 | func String(s []byte) string { 74 | if a := Lookup(s); a != 0 { 75 | return a.String() 76 | } 77 | return string(s) 78 | } 79 | -------------------------------------------------------------------------------- /vendor/google.golang.org/appengine/cloudsql/cloudsql.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Google Inc. All rights reserved. 2 | // Use of this source code is governed by the Apache 2.0 3 | // license that can be found in the LICENSE file. 4 | 5 | /* 6 | Package cloudsql exposes access to Google Cloud SQL databases. 7 | 8 | This package does not work in App Engine "flexible environment". 9 | 10 | This package is intended for MySQL drivers to make App Engine-specific 11 | connections. Applications should use this package through database/sql: 12 | Select a pure Go MySQL driver that supports this package, and use sql.Open 13 | with protocol "cloudsql" and an address of the Cloud SQL instance. 14 | 15 | A Go MySQL driver that has been tested to work well with Cloud SQL 16 | is the go-sql-driver: 17 | import "database/sql" 18 | import _ "github.com/go-sql-driver/mysql" 19 | 20 | db, err := sql.Open("mysql", "user@cloudsql(project-id:instance-name)/dbname") 21 | 22 | 23 | Another driver that works well with Cloud SQL is the mymysql driver: 24 | import "database/sql" 25 | import _ "github.com/ziutek/mymysql/godrv" 26 | 27 | db, err := sql.Open("mymysql", "cloudsql:instance-name*dbname/user/password") 28 | 29 | 30 | Using either of these drivers, you can perform a standard SQL query. 31 | This example assumes there is a table named 'users' with 32 | columns 'first_name' and 'last_name': 33 | 34 | rows, err := db.Query("SELECT first_name, last_name FROM users") 35 | if err != nil { 36 | log.Errorf(ctx, "db.Query: %v", err) 37 | } 38 | defer rows.Close() 39 | 40 | for rows.Next() { 41 | var firstName string 42 | var lastName string 43 | if err := rows.Scan(&firstName, &lastName); err != nil { 44 | log.Errorf(ctx, "rows.Scan: %v", err) 45 | continue 46 | } 47 | log.Infof(ctx, "First: %v - Last: %v", firstName, lastName) 48 | } 49 | if err := rows.Err(); err != nil { 50 | log.Errorf(ctx, "Row error: %v", err) 51 | } 52 | */ 53 | package cloudsql 54 | 55 | import ( 56 | "net" 57 | ) 58 | 59 | // Dial connects to the named Cloud SQL instance. 60 | func Dial(instance string) (net.Conn, error) { 61 | return connect(instance) 62 | } 63 | -------------------------------------------------------------------------------- /vendor/google.golang.org/appengine/cloudsql/cloudsql_classic.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Google Inc. All rights reserved. 2 | // Use of this source code is governed by the Apache 2.0 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build appengine 6 | 7 | package cloudsql 8 | 9 | import ( 10 | "net" 11 | 12 | "appengine/cloudsql" 13 | ) 14 | 15 | func connect(instance string) (net.Conn, error) { 16 | return cloudsql.Dial(instance) 17 | } 18 | -------------------------------------------------------------------------------- /vendor/google.golang.org/appengine/cloudsql/cloudsql_vm.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Google Inc. All rights reserved. 2 | // Use of this source code is governed by the Apache 2.0 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !appengine 6 | 7 | package cloudsql 8 | 9 | import ( 10 | "errors" 11 | "net" 12 | ) 13 | 14 | func connect(instance string) (net.Conn, error) { 15 | return nil, errors.New(`cloudsql: not supported in App Engine "flexible environment"`) 16 | } 17 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v2/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.4 5 | - 1.5 6 | - 1.6 7 | - 1.7 8 | - 1.8 9 | - 1.9 10 | - tip 11 | 12 | go_import_path: gopkg.in/yaml.v2 13 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v2/LICENSE.libyaml: -------------------------------------------------------------------------------- 1 | The following files were ported to Go from C files of libyaml, and thus 2 | are still covered by their original copyright and license: 3 | 4 | apic.go 5 | emitterc.go 6 | parserc.go 7 | readerc.go 8 | scannerc.go 9 | writerc.go 10 | yamlh.go 11 | yamlprivateh.go 12 | 13 | Copyright (c) 2006 Kirill Simonov 14 | 15 | Permission is hereby granted, free of charge, to any person obtaining a copy of 16 | this software and associated documentation files (the "Software"), to deal in 17 | the Software without restriction, including without limitation the rights to 18 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 19 | of the Software, and to permit persons to whom the Software is furnished to do 20 | so, subject to the following conditions: 21 | 22 | The above copyright notice and this permission notice shall be included in all 23 | copies or substantial portions of the Software. 24 | 25 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 26 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 27 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 28 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 29 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 30 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 31 | SOFTWARE. 32 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v2/NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2011-2016 Canonical Ltd. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v2/go.mod: -------------------------------------------------------------------------------- 1 | module "gopkg.in/yaml.v2" 2 | 3 | require ( 4 | "gopkg.in/check.v1" v0.0.0-20161208181325-20d25e280405 5 | ) 6 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v2/writerc.go: -------------------------------------------------------------------------------- 1 | package yaml 2 | 3 | // Set the writer error and return false. 4 | func yaml_emitter_set_writer_error(emitter *yaml_emitter_t, problem string) bool { 5 | emitter.error = yaml_WRITER_ERROR 6 | emitter.problem = problem 7 | return false 8 | } 9 | 10 | // Flush the output buffer. 11 | func yaml_emitter_flush(emitter *yaml_emitter_t) bool { 12 | if emitter.write_handler == nil { 13 | panic("write handler not set") 14 | } 15 | 16 | // Check if the buffer is empty. 17 | if emitter.buffer_pos == 0 { 18 | return true 19 | } 20 | 21 | if err := emitter.write_handler(emitter, emitter.buffer[:emitter.buffer_pos]); err != nil { 22 | return yaml_emitter_set_writer_error(emitter, "write error: "+err.Error()) 23 | } 24 | emitter.buffer_pos = 0 25 | return true 26 | } 27 | --------------------------------------------------------------------------------