-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdoc.go
49 lines (34 loc) · 1.31 KB
/
doc.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
/*
Package consent contains IAB consent string encode and decode implementations.
Version 1
Create a new consent (v1) with the consent.NewConsentV1 function:
cmpID := 1
cmpVersion := 1
consentScreen := byte(1)
lang := "EN"
vendorListVersion := 42
purposesAllowed := [24]bool{true, true, true, true}
allowedVendors := map[int]bool{10: true, 64: true}
c1 := consent.NewConsentV1(cmpID, cmpVersion, consentScreen, lang,
vendorListVersion, purposesAllowed, allowedVendors)
Decode an existing string with consent.ParseV1:
c2, err := consent.ParseV1("BOQ7WlgOQ7WlgABACDENABwAAABJOACgACAAQABA")
In both cases you can read and modify a struct as you want:
if c2.Vendors[55] {
// Vendor #55 is permitted
}
c2.Vendors[999] = true
c2.LastUpdated = time.Now()
At anytime export it as an IAB base64-encoded consent string:
c2.String()
Parsing a consent string if you don't know its version
c, err = consent.Parse("COtybn4PA_zT4KjACBENAPCIAEBAAECAAIAAAAAAAAAA")
println(c.Version()) // prints 2
// you can cast the parsed value to the matching Consent struct:
cv2, ok := v.(*ConsentV2)
You can also only parse the version information from a consent string
without parsing the whole string:
version, err = ParseConsentVersion("BOEFEAyOEFEAyAHABDENAI4AAAB9vABAASA")
println(version) // prints 1
*/
package consent