Get Raw data value from a go struct

2/26/2021

Im struggling to read value from yaml file, the value from the raw data struct , I need to get value like following , I want to get the cidr value and zone[0].name

package main

import (
	"fmt"
)


type Provider struct {
	Type string
    
	InfrastructureConfig *runtime.RawExtension

}

type RawExtension struct {
	// Raw is the underlying serialization of this object.
	// TODO: Determine how to detect ContentType and ContentEncoding of 'Raw' data.
	Raw []byte `json:"-" protobuf:"bytes,1,opt,name=raw"`
	Object Object `json:"-"`
}

func main() {
        // inside the row it should have the value from the yaml
       
	object.provider.InfrastructureConfig.Raw.
}

The yaml looks like following

 infrastructureConfig:
    kind: InfrastructureConfig
    apiVersion: v1
       networks:
          vpc:
            cidr: aaaa
          zones:
            - name: vm
              internal: true

if something isn't clear please let me know.

I've tried something like val,err := json.Marshal(object.provider.InfrastructureConfig.Raw)

In the val (using the debugger) I got the value "e30=" which is not what I want I want to get the cidr value which is aaaa

but I didn't able to get the data ...

This is the type of *runtime.RawExtension

https://github.com/kubernetes/apimachinery/blob/master/pkg/runtime/types.go#L94

-- JJD
amazon-web-services
azure
go
kubernetes
yaml

0 Answers