as3parse

package module
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

README

= GoAS3Parse

AS3 parsing module for Go

== Status

This project currently supports parsing a raw AS3 declaration into a
list of Go structs. It can parse a single declaration into a list of Tenant,
Application, and Virtual Server objects, including as many sub
properties/objects as possible. Focus is on LTM configuration for HTTPS virtual
servers.


== Usage

[source,go]
----
import (
	"encoding/json"
	"os"
	as3parse "github.com/allyn-bottorff/as3"

)


// Read in a JSON object file and store the contents as a map[string]interface{}
func readJson(filePath string) map[string]interface{} {
	f, err := os.ReadFile(filePath)
	if err != nil {
		log.Fatal("Failed to read AS3 JSON file.")
	}

	jsonMap := make(map[string]interface{})

	json.Unmarshal(f, &jsonMap)

	return jsonMap

}

func main() {

	// Create a map[string]interface{} 
	jsonMap := readJson("./path-to-as3.json")

	// Fill the AS3 Declaration with the parsed contents of the AS3 json
	dec := as3parse.ParseDec(jsonMap)

	// Print out basic statistic about the declaration
	dec.Summarize()

}
----

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Application

type Application struct {
	Name           string
	Monitors       []Monitor
	Pools          []Pool
	VirtualServers []VirtualServer
	Template       string `mapstructure:"template"`
}

AS3 Application. This is a container for virtual servers and related load balancing objects

func ParseApp

func ParseApp(rawApp map[string]interface{}, name string) Application

Parse application-specific fields (no nested objects)

func (*Application) CountMons

func (a *Application) CountMons() int

func (*Application) CountPools

func (a *Application) CountPools() int

func (*Application) CountVS

func (a *Application) CountVS() int

type Declaration

type Declaration struct {
	Tenants       []Tenant
	Label         string            `mapstructure:"label"`
	Remark        string            `mapstructure:"remark"`
	SchemaVersion string            `mapstructure:"schemaVersion"`
	Id            string            `mapstructure:"id"`
	UpdateMode    string            `mapstructure:"updateMode"`
	Controls      map[string]string `mapstructure:"controls"`
}

AS3 Declaration, reformatted to use lists of object types instead of individual named objects

func ParseDec

func ParseDec(rawDec map[string]interface{}) Declaration

Parse declaration-specific fields

func (*Declaration) PrintAll

func (dec *Declaration) PrintAll()

Print entire parsed declaration to the console in json format

func (*Declaration) PrintVSNames

func (dec *Declaration) PrintVSNames()

func (*Declaration) Summarize

func (dec *Declaration) Summarize()

type Member

type Member struct {
	AddressDiscovery string `mapstructure:"addressDiscovery"`
	ExternalId       string `mapstructure:"externalId"`
	Hostname         string `mapstructure:"hostname"`
	ServicePort      int    `mapstructure:"servicePort"`
}

type Monitor

type Monitor struct {
	Name        string `mapstructure:"name,omitempty"`
	Ciphers     string `mapstructure:"ciphers"`
	Class       string `mapstructure:"class"`
	Interval    int    `mapstructure:"interval"`
	MonitorType string `mapstructure:"monitorType"`
	Receive     string `mapstructure:"receive"`
	ReceiveDown string `mapstructure:"receiveDown"`
	Send        string `mapstructure:"send"`
	Timeout     string `mapstructure:"timeout"`
}

func ParseMon

func ParseMon(rawMon map[string]interface{}, name string) Monitor

type Pool

type Pool struct {
	Name              string              `mapstructure:"name,omitempty"`
	Class             string              `mapstructure:"class"`
	LoadBalancingMode string              `mapstructure:"loadBalancingMode"`
	Members           []Member            `mapstructure:"members"`
	Monitors          []map[string]string `mapstructure:"monitors"`
}

func ParsePool

func ParsePool(rawPool map[string]interface{}, name string) Pool

type Tenant

type Tenant struct {
	Name               string
	Applications       []Application
	DefaultRouteDomain int    `mapstructure:"defaultRouteDomain"`
	Enable             bool   `mapstructure:"enable"`
	OptimisticLockKey  string `mapstructure:"optimisticLockKey"`
}

AS3 Tenant, reformatted to use lists of object types instead of individual named objects

func ParseTenant

func ParseTenant(rawTenant map[string]interface{}, name string) Tenant

Parse tenant-specific fields (no nested objects)

func (*Tenant) Summarize

func (t *Tenant) Summarize()

type VirtualServer

type VirtualServer struct {
	Pool               string
	Name               string
	Layer4             string              `mapstructure:"layer4,omitempty"`
	AllowVlans         []map[string]string `mapstructure:"allowVlans"`
	Class              string              `mapstructure:"class"`
	ClientTLS          map[string]string   `mapstructure:"clientTLS"`
	ProfileTCP         string              `mapstructure:"profileTCP"`
	ProfileHTTP        map[string]string   `mapstructure:"profileHTTP,omitempty"`
	Redirect80         bool                `mapstructure:"redirect80"`
	ServerTLS          map[string]string   `mapstructure:"serverTLS"`
	VirtualAddresses   []string            `mapstructure:"virtualAddresses"`
	VirtualPort        int                 `mapstructure:"virtualPort"`
	PersistenceMethods []string            `mapstructure:"persistenceMethods,omitempty"`
}

This struct is a superset representing the possible keys for a virtual VirtualServer including Service_HTTP, Service_HTTPS, Service_TCP, Service_L4

func ParseVS

func ParseVS(rawVS map[string]interface{}, name string) VirtualServer

Jump to

Keyboard shortcuts

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