funcapi

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

README

Functional API variant example

Moves to functions all the way down in the stack, to avoid users having to choose between members and functions.

If functions used as per example, user doesn't need to know or invoke any structural aspects of the objects, all should be taken care of automatically.

All values can be set as interface{} type, with conversions of type and pointer handled automatically.

Incorrect types or incorrect properties will raise warnings but no errors or panics, and members will remain unset.

Objects prototyped are from the original b.go

build cmd/apibld/main.go for this example:

package main

import (
    "bytes"
    "encoding/json"
    "log"
    "os"

    api "github.com/nsip/sifxml2go/v3/funcapi"
)

func main() {

    // new object
    asf := &api.AggregateStatisticFact{}

    asf.Characteristics().
        Append().SetValue("one"). // add array members
        Append().SetValue("two"). // shorthand
        Append().SetValue("three").
        Append().AggregateCharacteristicInfoRefId().SetValue("four"). // fully qualified
        AggregateCharacteristicInfoRefId().Append().SetValue("five")  // alternative ordering, same output

    //
    // properties can be set independently of objects
    // all values are interfaces, managed by setters
    var bob string = "bob"
    var rid api.RefIdType = "abc-def-hij"
    props := []api.Prop{
        api.Prop{"Excluded", "bob"}, // ok, will be coerced to pointer
        api.Prop{"Excluded", 3},     // fails, generates warning, can't coerce
        api.Prop{"Excluded", bob},   // ok, converts to poiner
        api.Prop{"Excluded", &bob},  // ok, is accepted
        api.Prop{"Value", 21.8},     // ok, float pointer type
        api.Prop{"RefId", rid},      // ok, will be coerced
        api.Prop{"RefId", &rid},     // ok, is accepted
    }
    asf.SetProperties(props...). // set properties in bulk, any not relevant will be discarded with warnings
                    SetProperty("RefId", "ovverride-refid") // but can override specific

    // set internal object properties
    asf.StatsCohortYearLevelList().Append().CohortYearLevel().
        SetProperty("Code", "12")
    asf.StatsCohortYearLevelList().Append().CohortYearLevel().
        SetProperty("Code", "11")
    asf.StatsCohortYearLevelList().Last().CohortYearLevel().
        SetProperty("Code", "23") // fail, gnerates warning as is invalid codeset value

    // a full set of object properties
    scprops := []api.Prop{
        api.Prop{"StatsCohortId", "localid-a"},
        api.Prop{"StatsIndigenousStudentType", "type-1"},
        api.Prop{"CohortGender", "gender-x"},
        api.Prop{"DaysInReferencePeriod", 7},
        api.Prop{"PossibleSchoolDays", 25},
        api.Prop{"AttendanceDays", 12.5},
        api.Prop{"AttendanceLess90Percent", 6},
        api.Prop{"AttendanceGTE90Percent", 5},
        api.Prop{"PossibleSchoolDaysGT90PercentAttendance", 4},
    }
    asf.StatsCohortYearLevelList().Last().StatsCohortList().Append(). // add a new member
                                        StatsCohort().SetProperties(scprops...). // set in bulk
                                        SetProperty("AttendanceDays", 100.2)     // then override
    asf.StatsCohortYearLevelList().Last().StatsCohortList().Last(). // refer to same object
                                    SetProperties(scprops...).             // set in bulk..
                                    SetProperty("AttendanceDays", 10001.1) // then override
    asf.StatsCohortYearLevelList().Last().StatsCohortList().Append(). // add a new member
                                        StatsCohort().SetProperties(scprops...) // set in bulk
    //
    // render built object in json
    //
    b, err := json.Marshal(asf)
    if err != nil {
        log.Fatal(err)
    }
    var out bytes.Buffer
    json.Indent(&out, b, "=", "\t")
    out.WriteTo(os.Stdout)

}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AUCodeSetsYearLevelCodeTypeValues = map[string]struct{}{
	"0":        empty,
	"1":        empty,
	"2":        empty,
	"3":        empty,
	"4":        empty,
	"5":        empty,
	"6":        empty,
	"7":        empty,
	"8":        empty,
	"9":        empty,
	"10":       empty,
	"11":       empty,
	"12":       empty,
	"13":       empty,
	"K":        empty,
	"P":        empty,
	"K3":       empty,
	"K4":       empty,
	"CC":       empty,
	"PS":       empty,
	"UG":       empty,
	"11MINUS":  empty,
	"12PLUS":   empty,
	"UGJunSec": empty,
	"UGPri":    empty,
	"UGSec":    empty,
	"UGSnrSec": empty,
}

codeset as lookup map, faster than iterating array

Functions

func CodesetContains

func CodesetContains(codeset map[string]struct{}, value interface{}) bool

checks whether a codeset contains the supplied value

func FloatPointer

func FloatPointer(value interface{}) (*float64, bool)

allows float32 as well as 64

func IntPointer

func IntPointer(value interface{}) (*int, bool)

func StringPointer

func StringPointer(value interface{}) (*string, bool)

Types

type AUCodeSetsYearLevelCodeType

type AUCodeSetsYearLevelCodeType string

func AUCodeSetsYearLevelCodeTypePointer

func AUCodeSetsYearLevelCodeTypePointer(value interface{}) (*AUCodeSetsYearLevelCodeType, bool)

type AggregateStatisticFact

type AggregateStatisticFact struct {
	// contains filtered or unexported fields
}

object visible outside of package, but want all properties invisible, accessed only via functions

func (*AggregateStatisticFact) Characteristics

func (asf *AggregateStatisticFact) Characteristics() *CharacteristicsType

expose embedded object

func (*AggregateStatisticFact) MarshalJSON

func (asf *AggregateStatisticFact) MarshalJSON() ([]byte, error)

func (*AggregateStatisticFact) SetProperties

func (asf *AggregateStatisticFact) SetProperties(props ...Prop) *AggregateStatisticFact

allows for collection of key-value Prop{} objects to be used to set many properties at once.

func (*AggregateStatisticFact) SetProperty

func (asf *AggregateStatisticFact) SetProperty(key string, value interface{}) *AggregateStatisticFact

handle the setting of all properties props can be any type and pointers or not helper utilities will convert to correct types an return pointers as required

func (*AggregateStatisticFact) StatsCohortYearLevelList

func (asf *AggregateStatisticFact) StatsCohortYearLevelList() *StatsCohortYearLevelListType

expose embedded object

func (*AggregateStatisticFact) UnmarshalJSON

func (asf *AggregateStatisticFact) UnmarshalJSON(b []byte) error

need 'custom' marshal/unmarshal as data all in embedded object

outer container object also has pesc-compliant single member that refelcts the sif object name

type CharacteristicsType

type CharacteristicsType struct {
	// contains filtered or unexported fields
}

public object

func (*CharacteristicsType) AggregateCharacteristicInfoRefId

func (t *CharacteristicsType) AggregateCharacteristicInfoRefId() *CharacteristicsType

exposes the internal array

func (*CharacteristicsType) Append

syntactic sugar, not strictly necessary but helps the user

func (*CharacteristicsType) SetValue

func (t *CharacteristicsType) SetValue(v interface{}) *CharacteristicsType

add a value to the internal array

type GUIDType

type GUIDType string

indirection types from original generated code

type LocalIdType

type LocalIdType string

func LocalIdPointer

func LocalIdPointer(value interface{}) (*LocalIdType, bool)

allows strings as well as derived types

type MsgIdType

type MsgIdType GUIDType

type Prop

type Prop struct {
	Key   string
	Value interface{}
}

wrapper for key/val property

type RefIdType

type RefIdType GUIDType

func RefIdPointer

func RefIdPointer(value interface{}) (*RefIdType, bool)

allows strings as well as derived types

type StatsCohortListType

type StatsCohortListType struct {
	// contains filtered or unexported fields
}

external type

func (*StatsCohortListType) Append

helper for user

func (*StatsCohortListType) Last

access the most recently added member of the list

func (*StatsCohortListType) StatsCohort

func (t *StatsCohortListType) StatsCohort() *StatsCohortType

expose the internal list

type StatsCohortType

type StatsCohortType struct {
	// contains filtered or unexported fields
}

externally visible object

func (*StatsCohortType) SetProperties

func (t *StatsCohortType) SetProperties(props ...Prop) *StatsCohortType

lets user set many properties at once

func (*StatsCohortType) SetProperty

func (t *StatsCohortType) SetProperty(key string, value interface{}) *StatsCohortType

allow user to set object properies, handle type conversions etc. for user

type StatsCohortYearLevelListType

type StatsCohortYearLevelListType struct {
	// contains filtered or unexported fields
}

exposed object

func (*StatsCohortYearLevelListType) Append

if the type of the list is a complex object append creates a member of that type, initilaises the list if necessary

func (*StatsCohortYearLevelListType) Last

allows reference to most recently added memebr of list, allows setting of (for example) another object that may be part of the member

type StatsCohortYearLevelType

type StatsCohortYearLevelType struct {
	// contains filtered or unexported fields
}

external type

func (*StatsCohortYearLevelType) CohortYearLevel

func (s *StatsCohortYearLevelType) CohortYearLevel() *YearLevelType

expose member object, create if needed

func (*StatsCohortYearLevelType) StatsCohortList

func (t *StatsCohortYearLevelType) StatsCohortList() *StatsCohortListType

expose member object, create if needed

type YearLevelType

type YearLevelType struct {
	// contains filtered or unexported fields
}

externally visible object

func (*YearLevelType) SetProperty

func (y *YearLevelType) SetProperty(key string, value interface{}) *YearLevelType

allows user to set internal property, in this case shows how codesets can be checked

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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