openrtb

module
v14.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 2, 2021 License: Unlicense

README

openrtb GoDoc Build Status

OpenRTB, AdCOM and OpenRTB Dynamic Native Ads types for Go programming language

Requires Go 1.8+

Go 1.8+ is needed for proper Ext json.RawMessage marshaling: non-pointer json.RawMessage is marshaled as base64 string prior to Go 1.8.

This library uses json.RawMessage since v10.0.0.

This library is tested with Go 1.9+ since v12.0.0.

Using

go get -u "github.com/mxmCherry/openrtb/v14/..."
import (
	openrtb2 "github.com/mxmCherry/openrtb/v14/openrtb2"

	openrtb3 "github.com/mxmCherry/openrtb/v14/openrtb3"
	adcom1 "github.com/mxmCherry/openrtb/v14/adcom1"

	native1 "github.com/mxmCherry/openrtb/v14/native1"
	nreq "github.com/mxmCherry/openrtb/v14/native1/request"
	nres "github.com/mxmCherry/openrtb/v14/native1/response"
)

This repo follows semver - see releases. Master always contains latest code, so better use some package manager to vendor specific version.

Guidelines

Naming convention

  • UpperCamelCase
  • Capitalized abbreviations (e.g., AT, COPPA, PMP etc.)
  • Capitalized ID keys

Types

  • Key types should be chosen according to OpenRTB specification (attribute types)
  • Numeric types:
    • int8 - short enums (with values <= 127), boolean-like attributes (like BidRequest.test)
    • int64 - other integral types
    • float64 - coordinates, prices etc.
  • Enums:
    • all enums, described in section 5, must be typed with section name singularized (e.g., "5.2 Banner Ad Types" -> type BannerAdType int8)
    • all typed enums must have constants for each element, prefixed with type name (e.g., "5.2 Banner Ad Types - XHTML Text Ad (usually mobile)" -> const BannerAdTypeXHTMLTextAd BannerAdType = 1)
    • never use iota for enum constants
    • OpenRTB (2.x) section "5.1 Content Categories" should remain untyped and have no constants

Pointers/omitempty

Pointer Omitempty When to use Example
no no required in spec Audio.mimes
yes yes required in spec, but is a part of mutually-exclusive group Imp.{banner,video,audio,native}
no yes zero value ("", 0) is useless / has no meaning Device.ua
yes yes zero value ("", 0) or value absence (null) has special meaning Device.{dnt,lmt}

Using both pointer and omitempty is mostly just to save traffic / generate more "canonical" (strict) JSON.

Documentation (pkg.go.dev)

  • Godoc: documenting Go code
  • Each entity (type, struct key or constant) should be documented
  • Comments for entities should be copy-pasted "as-is" from OpenRTB specification (except section 5 - replace "table" with "list" there; ideally, each sentence must be on a new line)

Code organization

  • Each RTB type should be kept in its own file, named after type
  • File names are in underscore_case, e.g., type BidRequest should be declared in bid_request.go
  • go fmt your code
  • EditorConfig (not required, but useful)

Directories

Path Synopsis
Package adcom1 provides AdCOM 1.0 types https://iabtechlab.com/standards/openmedia/ https://github.com/InteractiveAdvertisingBureau/AdCOM
Package adcom1 provides AdCOM 1.0 types https://iabtechlab.com/standards/openmedia/ https://github.com/InteractiveAdvertisingBureau/AdCOM
Package native1 provides OpenRTB Native 1.2 enums (section "7 Reference Lists/Enumerations") https://iabtechlab.com/standards/openrtb-native/ https://iabtechlab.com/wp-content/uploads/2016/07/OpenRTB-Native-Ads-Specification-Final-1.2.pdf
Package native1 provides OpenRTB Native 1.2 enums (section "7 Reference Lists/Enumerations") https://iabtechlab.com/standards/openrtb-native/ https://iabtechlab.com/wp-content/uploads/2016/07/OpenRTB-Native-Ads-Specification-Final-1.2.pdf
request
Package request provides OpenRTB Native 1.2 request types (section "4 Native Ad Request Markup Details") https://iabtechlab.com/standards/openrtb-native/ https://iabtechlab.com/wp-content/uploads/2016/07/OpenRTB-Native-Ads-Specification-Final-1.2.pdf
Package request provides OpenRTB Native 1.2 request types (section "4 Native Ad Request Markup Details") https://iabtechlab.com/standards/openrtb-native/ https://iabtechlab.com/wp-content/uploads/2016/07/OpenRTB-Native-Ads-Specification-Final-1.2.pdf
response
Package response provides OpenRTB Native 1.2 response types (section "5 Native Ad Response Markup Details") https://iabtechlab.com/standards/openrtb-native/ https://iabtechlab.com/wp-content/uploads/2016/07/OpenRTB-Native-Ads-Specification-Final-1.2.pdf
Package response provides OpenRTB Native 1.2 response types (section "5 Native Ad Response Markup Details") https://iabtechlab.com/standards/openrtb-native/ https://iabtechlab.com/wp-content/uploads/2016/07/OpenRTB-Native-Ads-Specification-Final-1.2.pdf
Package openrtb2 provides OpenRTB 2.5 types https://iabtechlab.com/standards/openrtb/ https://iabtechlab.com/wp-content/uploads/2016/07/OpenRTB-API-Specification-Version-2-5-FINAL.pdf
Package openrtb2 provides OpenRTB 2.5 types https://iabtechlab.com/standards/openrtb/ https://iabtechlab.com/wp-content/uploads/2016/07/OpenRTB-API-Specification-Version-2-5-FINAL.pdf
Package openrtb3 provides OpenRTB 3.0 types https://iabtechlab.com/standards/openrtb/ https://github.com/InteractiveAdvertisingBureau/openrtb
Package openrtb3 provides OpenRTB 3.0 types https://iabtechlab.com/standards/openrtb/ https://github.com/InteractiveAdvertisingBureau/openrtb

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL