项目作者: hybridtheory

项目描述 :
A Go wrapper over the LiveRamp implementation of the IAB Consent String Specs (v1.1 and v2)
高级语言: Go
项目地址: git://github.com/hybridtheory/iab-tcf.git
创建时间: 2020-05-06T11:25:25Z
项目社区:https://github.com/hybridtheory/iab-tcf

开源协议:MIT License

下载


iab-tcf CircleCI

Go code to parse IAB v1/v2 consent based on github.com/LiveRamp/iabconsent
library.

This package is just a wrapper on their amazing work to fill our needs.

Usage

Install

  1. go get github.com/hybridtheory/iab-tcf

Example

  1. package main
  2. import (
  3. "fmt"
  4. iab "github.com/hybridtheory/iab-tcf"
  5. )
  6. func main() {
  7. encoded := "COyt4MbOyt4MbMOAAAENAiCgAIAAAAAAAAAAADEAAgIAAAAAAAA.YAAAAAAAAAA"
  8. consent, err := iab.NewConsent(encoded)
  9. }

CMP vendor list

In order to validate if the CMP received belongs to a valid id there’s a loader integrated
with the library.

  1. package main
  2. import (
  3. "fmt"
  4. iab "github.com/hybridtheory/iab-tcf"
  5. cmp "github.com/hybridtheory/iab-tcf/cmp"
  6. )
  7. func main() {
  8. cmp.NewLoader().LoadIDs()
  9. consent, err := iab.NewConsent(encoded)
  10. consent.IsCMPValid() // This will return true/false depending on the ids loaded.
  11. }

If instead of the default vendor list https://cmplist.consensu.org/v2/cmp-list.json
we want to use our own, we can use an option:

  1. err := cmp.NewLoader(cmp.WithURL("https://example.com/cmp-list.json")).LoadIDs()

The format of the JSON must be the same.

If we want to use our own list of valid CMPs we can simply set the variable:

  1. cmp.ValidCMPs = []int{1, 123}

Testing

We use Ginkgo and Gomega
for testing purposes.

  1. ginkgo ./...