-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_model.go
136 lines (119 loc) · 3.91 KB
/
api_model.go
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//------------------------------------------------------------------------------
// From http://github.com/heitorperalles/checkCpfRestApiGoCgo
//
// Distributed under The MIT License (MIT) <http://opensource.org/licenses/MIT>
//
// Copyright (c) 2020 Heitor Peralles <[email protected]>
//
// 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:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// 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.
//------------------------------------------------------------------------------
package main
// Subject model (REQUEST specification)
//
// Represents how subject data must be submitted to the API.
//
// Request example:
// {
// "name":"Heitor Peralles",
// "cpf":"40442820135",
// "rg":
// {
// "number":"209921899",
// "issued":"2020/5/20",
// "by":"DETRAN-RJ"
// }
// }
//
type Subject struct {
// Subject's Name
//
// Required: False
// Example: Heitor Peralles
Name string `json:"name,omitempty"`
// Subject's CPF (Brazilian Physical Person Register)
//
// Required: True
// Example: 404.428.201-35
// Example: 40442820135
Cpf string `json:"cpf,omitempty"`
// Subject's RG (General Registry)
//
// Required: False
// Example: [RG struct]
RG *RG `json:"rg,omitempty"`
}
// RG model
// Represents how General Registry data must be submitted.
type RG struct {
// General Registry number
//
// Required: False
// Example: 209921899
Number string `json:"number,omitempty"`
// General Registry issued date
//
// Required: False
// Example: 2020/05/20
Issued string `json:"issued,omitempty"`
// General Registry issuing entity
//
// Required: False
// Example: DETRAN-RJ
Entity string `json:"entity,omitempty"`
}
// Verdict model (RESPONSE specification)
//
// Represents how API requests will be replyed.
//
// Response example:
// {
// "status":"False",
// "message":"Invalid CPF Format."
// }
//
type Verdict struct {
// Status (True if register OK, False otherwise)
//
// Required: True
// Example: True
// Example: False
Status string `json:"status,omitempty"`
// Error Message
//
// Required: False
// Example: Invalid CPF Format
Message string `json:"message,omitempty"`
}
// Messages to be attached on RESPONSE
//
// Possible messages to each expected status code
const (
// Response message for status code 400
INVALID_CPF_FORMAT_MESSAGE string = "Invalid CPF Format."
// Response message for status code 400
CPF_NOT_PROVIDED_MESSAGE string = "Required CPF field not present."
// Response message for status code 400
INVALID_JSON_FORMAT_MESSAGE string = "Invalid JSON provided."
// Response message for status code 403
SUBJECT_REJECTED_MESSAGE string = "CPF not regular or not existant."
// Response message for status code 500
EXTERNAL_SERVER_ERROR_MESSAGE string = "Problem trying to comunicate with other entities."
// Response message for any other status code
UNKNOWN_ERROR_MESSAGE string = "Unknown error."
)