OpenRTB v2.5 / Native v1.2 types for Go programming language (Golang)
Clone or download
Permalink
Failed to load latest commit information.
native native/README: added godoc badge Mar 4, 2018
testdata Polish READMEs Nov 13, 2017
.editorconfig editorconfig: added basic config Oct 12, 2018
.travis.yml travis: test only with go 1.8.x (minimal required version) and 1.x (l… Oct 12, 2018
LICENSE Initial commit Apr 28, 2015
README.md README: OCD: sort types by, umm, size Oct 12, 2018
ad_position.go Val() helper method for nullable enum types Oct 26, 2017
api_framework.go Enums (except 5.1 Content Categories) + some fixes (missing attrs) Oct 1, 2017
app.go Switch from custom RawJSON to json.RawMessage Mar 3, 2018
audio.go Switch from custom RawJSON to json.RawMessage Mar 3, 2018
banner.go Switch from custom RawJSON to json.RawMessage Mar 3, 2018
banner_ad_type.go Enums (except 5.1 Content Categories) + some fixes (missing attrs) Oct 1, 2017
bid.go Switch from custom RawJSON to json.RawMessage Mar 3, 2018
bid_request.go Switch from custom RawJSON to json.RawMessage Mar 3, 2018
bid_request_test.go More test reorg Nov 13, 2017
bid_response.go Switch from custom RawJSON to json.RawMessage Mar 3, 2018
bid_response_test.go More test reorg Nov 13, 2017
companion_type.go Enums (except 5.1 Content Categories) + some fixes (missing attrs) Oct 1, 2017
connection_type.go Val() helper method for nullable enum types Oct 26, 2017
content.go Switch from custom RawJSON to json.RawMessage Mar 3, 2018
content_context.go Enums (except 5.1 Content Categories) + some fixes (missing attrs) Oct 1, 2017
content_delivery_method.go Enums (except 5.1 Content Categories) + some fixes (missing attrs) Oct 1, 2017
creative_attribute.go Enums (except 5.1 Content Categories) + some fixes (missing attrs) Oct 1, 2017
data.go Switch from custom RawJSON to json.RawMessage Mar 3, 2018
deal.go Switch from custom RawJSON to json.RawMessage Mar 3, 2018
device.go apply the same rule on DNT as for Lmt Oct 11, 2018
device_type.go Enums (except 5.1 Content Categories) + some fixes (missing attrs) Oct 1, 2017
expandable_direction.go Enums (except 5.1 Content Categories) + some fixes (missing attrs) Oct 1, 2017
feed_type.go Enums (except 5.1 Content Categories) + some fixes (missing attrs) Oct 1, 2017
format.go Switch from custom RawJSON to json.RawMessage Mar 3, 2018
geo.go Switch from custom RawJSON to json.RawMessage Mar 3, 2018
imp.go Switch from custom RawJSON to json.RawMessage Mar 3, 2018
ip_location_service.go Enums (except 5.1 Content Categories) + some fixes (missing attrs) Oct 1, 2017
iqg_media_rating.go Enums (except 5.1 Content Categories) + some fixes (missing attrs) Oct 1, 2017
location_type.go Enums (except 5.1 Content Categories) + some fixes (missing attrs) Oct 1, 2017
loss_reason_code.go Enums (except 5.1 Content Categories) + some fixes (missing attrs) Oct 1, 2017
metric.go Switch from custom RawJSON to json.RawMessage Mar 3, 2018
native.go Switch from custom RawJSON to json.RawMessage Mar 3, 2018
no_bid_reason_code.go Val() helper method for nullable enum types Oct 26, 2017
openrtb.go README update - guidelines for enums Oct 1, 2017
openrtb_suite_test.go Reorganized tests (refactoring only) Nov 13, 2017
playback_cessation_mode.go Enums (except 5.1 Content Categories) + some fixes (missing attrs) Oct 1, 2017
playback_method.go Enums (except 5.1 Content Categories) + some fixes (missing attrs) Oct 1, 2017
pmp.go Switch from custom RawJSON to json.RawMessage Mar 3, 2018
producer.go Switch from custom RawJSON to json.RawMessage Mar 3, 2018
production_quality.go Val() helper method for nullable enum types Oct 26, 2017
protocol.go Enums (except 5.1 Content Categories) + some fixes (missing attrs) Oct 1, 2017
ptr.go OCD: Ptr helpers: type name comes first Oct 19, 2017
publisher.go Switch from custom RawJSON to json.RawMessage Mar 3, 2018
regs.go Switch from custom RawJSON to json.RawMessage Mar 3, 2018
seat_bid.go Switch from custom RawJSON to json.RawMessage Mar 3, 2018
segment.go Switch from custom RawJSON to json.RawMessage Mar 3, 2018
site.go Switch from custom RawJSON to json.RawMessage Mar 3, 2018
source.go Switch from custom RawJSON to json.RawMessage Mar 3, 2018
start_delay.go Val() helper method for nullable enum types Oct 26, 2017
user.go Switch from custom RawJSON to json.RawMessage Mar 3, 2018
video.go Switch from custom RawJSON to json.RawMessage Mar 3, 2018
video_linearity.go Enums (except 5.1 Content Categories) + some fixes (missing attrs) Oct 1, 2017
video_placement_type.go Enums (except 5.1 Content Categories) + some fixes (missing attrs) Oct 1, 2017
volume_normalization_mode.go Val() helper method for nullable enum types Oct 26, 2017

README.md

openrtb GoDoc Build Status

OpenRTB v2.5 types for Go programming language (Golang)

Also includes OpenRTB Dynamic Native Ads API Specification Version 1.2 types:

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.

Using

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

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 - time, duration, length, unbound enums (like BidRequest.at - exchange-specific auctions types are > 500)
    • uint64 - width, height, bitrate etc. (unbound positive numbers)
    • 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
    • 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 (godoc)

  • 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)