This repository has been archived by the owner on Aug 18, 2021. It is now read-only.
/
validation.go
57 lines (52 loc) · 1.58 KB
/
validation.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
// Copyright © 2017 The Things Network
// Use of this source code is governed by the MIT license that can be found in the LICENSE file.
package router
import (
"github.com/TheThingsNetwork/api"
"github.com/TheThingsNetwork/ttn/utils/errors"
)
// Validate implements the api.Validator interface
func (m *UplinkMessage) Validate() error {
if err := api.NotNilAndValid(m.GatewayMetadata, "GatewayMetadata"); err != nil {
return err
}
if err := api.NotNilAndValid(m.ProtocolMetadata, "ProtocolMetadata"); err != nil {
return err
}
if m.Message != nil {
if err := m.Message.Validate(); err != nil {
return errors.NewErrInvalidArgument("Message", err.Error())
}
}
return nil
}
// Validate implements the api.Validator interface
func (m *DownlinkMessage) Validate() error {
if err := api.NotNilAndValid(m.ProtocolConfiguration, "ProtocolConfiguration"); err != nil {
return err
}
if err := api.NotNilAndValid(m.GatewayConfiguration, "GatewayConfiguration"); err != nil {
return err
}
if m.Message != nil {
if err := m.Message.Validate(); err != nil {
return errors.NewErrInvalidArgument("Message", err.Error())
}
}
return nil
}
// Validate implements the api.Validator interface
func (m *DeviceActivationRequest) Validate() error {
if err := api.NotNilAndValid(m.GatewayMetadata, "GatewayMetadata"); err != nil {
return err
}
if err := api.NotNilAndValid(m.ProtocolMetadata, "ProtocolMetadata"); err != nil {
return err
}
if m.Message != nil {
if err := m.Message.Validate(); err != nil {
return errors.NewErrInvalidArgument("Message", err.Error())
}
}
return nil
}