-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathurl.go
35 lines (29 loc) · 1001 Bytes
/
url.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
// Copyright 2020 Joakim Kennedy. All rights reserved. Use of
// this source code is governed by the included BSD license.
package stix2
import "fmt"
// URL object represents the properties of a uniform resource locator (URL).
type URL struct {
STIXCyberObservableObject
// Value specifies the value of the URL. The value of this property MUST
// conform to RFC3986, more specifically section 1.1.3 with reference to
// the definition for "Uniform Resource Locator".
Value string `json:"value"`
}
func (o *URL) MarshalJSON() ([]byte, error) {
return marshalToJSONHelper(o)
}
// NewURL creates a new URL object.
func NewURL(value string, opts ...STIXOption) (*URL, error) {
if value == "" {
return nil, ErrInvalidParameter
}
base := newSTIXCyberObservableObject(TypeURL)
obj := &URL{
STIXCyberObservableObject: base,
Value: value,
}
err := applyOptions(obj, opts)
obj.ID = NewObservableIdentifier(fmt.Sprintf("[\"%s\"]", value), TypeURL)
return obj, err
}