Skip to content

joeig/go-vast

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Mar 13, 2025
3f3ecd0 · Mar 13, 2025

History

29 Commits
Mar 13, 2025
Sep 11, 2023
Sep 11, 2023
Sep 11, 2023
Sep 11, 2023
Sep 11, 2023
Apr 10, 2024
Mar 13, 2025
Mar 13, 2025
Sep 11, 2023
Sep 11, 2023
Sep 11, 2023

Repository files navigation

go-vast

Go package to parse, manipulate and build Digital Video Ad Serving Templates (VAST). The currently supported version is VAST 4.2.

Test coverage Go Report Card PkgGoDev

Usage

go get -u go.eigsys.de/go-vast

Important note on CDATA handling of encoding/xml

The encoding/xml package merges CDATA sections with surrounding text. This can lead to unexpected results when parsing VAST files.

Consider the following example:

          <JavaScriptResource>
            <![CDATA[https://verificationcompany1.com/verification_script1.js]]>
          </JavaScriptResource>

After parsing JavaScriptResource, the value is:

\n            https://verificationcompany1.com/verification_script1.js\n          

If you need the content without the Unicode spaces, consider using strings.TrimSpace(). For more information, see #43168.

Examples

A complete list of examples is available in the package reference.

Create empty VAST

package main

import (
	"go.eigsys.de/go-vast"
)

func main() {
	example := vast.New()
	example.Version = vast.VAST42Version
}

Read VAST from file

package main

import (
	"go.eigsys.de/go-vast"
	"log"
	"os"
)

func main() {
	handle, err := os.Open("vast.xml")
	if err != nil {
		log.Fatalf("%v", err)
	}
	
	example, err := vast.Read(handle)
	if err != nil {
		log.Fatalf("%v", err)
	}
}

Marshal VAST

package main

import (
	"go.eigsys.de/go-vast"
	"log"
)

func main() {
	example := vast.New()

	exampleBytes, err := example.Bytes()
	if err != nil {
		log.Fatalf("%v", err)
	}
}