aboutsummaryrefslogtreecommitdiffstats
path: root/modules/base/base.go
blob: 3e80a436e4c2d33cbe5363610159f3b39c9d6bf5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2014 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package base

type (
	// Type TmplData represents data in the templates.
	TmplData map[string]interface{}
)

// __________.__            .___.__
// \______   \__| ____    __| _/|__| ____    ____
//  |    |  _/  |/    \  / __ | |  |/    \  / ___\
//  |    |   \  |   |  \/ /_/ | |  |   |  \/ /_/  >
//  |______  /__|___|  /\____ | |__|___|  /\___  /
//         \/        \/      \/         \//_____/

// Errors represents the contract of the response body when the
// binding step fails before getting to the application.
type BindingErrors struct {
	Overall map[string]string `json:"overall"`
	Fields  map[string]string `json:"fields"`
}

// Total errors is the sum of errors with the request overall
// and errors on individual fields.
func (err BindingErrors) Count() int {
	return len(err.Overall) + len(err.Fields)
}

func (this *BindingErrors) Combine(other BindingErrors) {
	for key, val := range other.Fields {
		if _, exists := this.Fields[key]; !exists {
			this.Fields[key] = val
		}
	}
	for key, val := range other.Overall {
		if _, exists := this.Overall[key]; !exists {
			this.Overall[key] = val
		}
	}
}

const (
	BindingRequireError         string = "Required"
	BindingAlphaDashError       string = "AlphaDash"
	BindingMinSizeError         string = "MinSize"
	BindingMaxSizeError         string = "MaxSize"
	BindingEmailError           string = "Email"
	BindingUrlError             string = "Url"
	BindingDeserializationError string = "DeserializationError"
	BindingIntegerTypeError     string = "IntegerTypeError"
	BindingBooleanTypeError     string = "BooleanTypeError"
	BindingFloatTypeError       string = "FloatTypeError"
)

var GoGetMetas = make(map[string]bool)