OpenRTB v2.5 / Native v1.2 types for Go programming language (Golang)
Перейти к файлу
Anton Sibilev 5e8eaedcb4
Merge pull request #3 from Applifier/chore/test_easyjson
Use easyjson for bid request and response
2019-09-11 16:24:35 +03:00
adcom1 adcom1: rename creative subtypes to sound more natural 2018-12-30 13:47:19 +02:00
native1 cosmetics: polishing native godoc pkg comments even further 2018-12-30 13:32:46 +02:00
openrtb2 add generated bid_response_easyjson.go 2019-09-06 17:40:55 +03:00
openrtb3 cosmetics: make sure that every Go pkg README has godoc badge 2018-12-30 13:36:39 +02:00
.editorconfig editorconfig: added basic config 2018-10-12 22:21:17 +03:00
.travis.yml travis: test with 1.9.x as oldest supported Go version 2018-12-24 17:24:03 +02:00
LICENSE Initial commit 2015-04-28 20:07:07 +03:00
README.md Merge branch 'master' into chore/update-upstream-cf3a19f 2019-07-01 16:04:03 +03:00

README.md

openrtb GoDoc Build Status

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

Note

This repository is a fork with changes in types.

For example, in original package Imp.Bidfloor is float64, which is 0 by default after unmarshaling in case field is missing from bid request. For data science purposes we want to know was it actually 0 or missing, so we changed float64 to *float64.

Same can be done for other fields as well, if needed.

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/..."
import (
	openrtb2 "github.com/mxmCherry/openrtb/openrtb2"

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

	native1 "github.com/mxmCherry/openrtb/native1"
	nreq "github.com/mxmCherry/openrtb/native1/request"
	nres "github.com/mxmCherry/openrtb/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 (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)