How to use UnmarshalJSON method of metrics Package

Best K6 code snippet using metrics.UnmarshalJSON

model.go

Source:model.go Github

copy

Full Screen

...94 return o95}96type rawPublicKeyEntry PublicKeyEntry97//98// UnmarshalJSON is defined for proper JSON decoding of a PublicKeyEntry99//100func (pTypeDef *PublicKeyEntry) UnmarshalJSON(b []byte) error {101 var r rawPublicKeyEntry102 err := json.Unmarshal(b, &r)103 if err == nil {104 o := PublicKeyEntry(r)105 *pTypeDef = o106 err = pTypeDef.Validate()107 }108 return err109}110//111// Validate - checks for missing required fields, etc112//113func (pTypeDef *PublicKeyEntry) Validate() error {114 if pTypeDef.Key == "" {115 return fmt.Errorf("PublicKeyEntry.key is missing but is a required field")116 } else {117 val := rdl.Validate(ZTSSchema(), "String", pTypeDef.Key)118 if !val.Valid {119 return fmt.Errorf("PublicKeyEntry.key does not contain a valid String (%v)", val.Error)120 }121 }122 if pTypeDef.Id == "" {123 return fmt.Errorf("PublicKeyEntry.id is missing but is a required field")124 } else {125 val := rdl.Validate(ZTSSchema(), "String", pTypeDef.Id)126 if !val.Valid {127 return fmt.Errorf("PublicKeyEntry.id does not contain a valid String (%v)", val.Error)128 }129 }130 return nil131}132//133// ServiceIdentity - The representation of the service identity object.134//135type ServiceIdentity struct {136 //137 // the full name of the service, i.e. "sports.storage"138 //139 Name ServiceName `json:"name"`140 //141 // array of public keys for key rotation142 //143 PublicKeys []*PublicKeyEntry `json:"publicKeys,omitempty" rdl:"optional"`144 //145 // if present, then this service can provision tenants via this endpoint.146 //147 ProviderEndpoint string `json:"providerEndpoint,omitempty" rdl:"optional"`148 //149 // the timestamp when this entry was last modified150 //151 Modified *rdl.Timestamp `json:"modified,omitempty" rdl:"optional"`152 //153 // the path of the executable that runs the service154 //155 Executable string `json:"executable,omitempty" rdl:"optional"`156 //157 // list of host names that this service can run on158 //159 Hosts []string `json:"hosts,omitempty" rdl:"optional"`160 //161 // local (unix) user name this service can run as162 //163 User string `json:"user,omitempty" rdl:"optional"`164 //165 // local (unix) group name this service can run as166 //167 Group string `json:"group,omitempty" rdl:"optional"`168}169//170// NewServiceIdentity - creates an initialized ServiceIdentity instance, returns a pointer to it171//172func NewServiceIdentity(init ...*ServiceIdentity) *ServiceIdentity {173 var o *ServiceIdentity174 if len(init) == 1 {175 o = init[0]176 } else {177 o = new(ServiceIdentity)178 }179 return o180}181type rawServiceIdentity ServiceIdentity182//183// UnmarshalJSON is defined for proper JSON decoding of a ServiceIdentity184//185func (pTypeDef *ServiceIdentity) UnmarshalJSON(b []byte) error {186 var r rawServiceIdentity187 err := json.Unmarshal(b, &r)188 if err == nil {189 o := ServiceIdentity(r)190 *pTypeDef = o191 err = pTypeDef.Validate()192 }193 return err194}195//196// Validate - checks for missing required fields, etc197//198func (pTypeDef *ServiceIdentity) Validate() error {199 if pTypeDef.Name == "" {200 return fmt.Errorf("ServiceIdentity.name is missing but is a required field")201 } else {202 val := rdl.Validate(ZTSSchema(), "ServiceName", pTypeDef.Name)203 if !val.Valid {204 return fmt.Errorf("ServiceIdentity.name does not contain a valid ServiceName (%v)", val.Error)205 }206 }207 return nil208}209//210// ServiceIdentityList - The representation for an enumeration of services in211// the namespace.212//213type ServiceIdentityList struct {214 //215 // list of service names216 //217 Names []EntityName `json:"names"`218}219//220// NewServiceIdentityList - creates an initialized ServiceIdentityList instance, returns a pointer to it221//222func NewServiceIdentityList(init ...*ServiceIdentityList) *ServiceIdentityList {223 var o *ServiceIdentityList224 if len(init) == 1 {225 o = init[0]226 } else {227 o = new(ServiceIdentityList)228 }229 return o.Init()230}231//232// Init - sets up the instance according to its default field values, if any233//234func (pTypeDef *ServiceIdentityList) Init() *ServiceIdentityList {235 if pTypeDef.Names == nil {236 pTypeDef.Names = make([]EntityName, 0)237 }238 return pTypeDef239}240type rawServiceIdentityList ServiceIdentityList241//242// UnmarshalJSON is defined for proper JSON decoding of a ServiceIdentityList243//244func (pTypeDef *ServiceIdentityList) UnmarshalJSON(b []byte) error {245 var r rawServiceIdentityList246 err := json.Unmarshal(b, &r)247 if err == nil {248 o := ServiceIdentityList(r)249 *pTypeDef = *((&o).Init())250 err = pTypeDef.Validate()251 }252 return err253}254//255// Validate - checks for missing required fields, etc256//257func (pTypeDef *ServiceIdentityList) Validate() error {258 if pTypeDef.Names == nil {259 return fmt.Errorf("ServiceIdentityList: Missing required field: names")260 }261 return nil262}263//264// HostServices - The representation for an enumeration of services authorized265// to run on a specific host.266//267type HostServices struct {268 //269 // name of the host270 //271 Host string `json:"host"`272 //273 // list of service names authorized to run on this host274 //275 Names []EntityName `json:"names"`276}277//278// NewHostServices - creates an initialized HostServices instance, returns a pointer to it279//280func NewHostServices(init ...*HostServices) *HostServices {281 var o *HostServices282 if len(init) == 1 {283 o = init[0]284 } else {285 o = new(HostServices)286 }287 return o.Init()288}289//290// Init - sets up the instance according to its default field values, if any291//292func (pTypeDef *HostServices) Init() *HostServices {293 if pTypeDef.Names == nil {294 pTypeDef.Names = make([]EntityName, 0)295 }296 return pTypeDef297}298type rawHostServices HostServices299//300// UnmarshalJSON is defined for proper JSON decoding of a HostServices301//302func (pTypeDef *HostServices) UnmarshalJSON(b []byte) error {303 var r rawHostServices304 err := json.Unmarshal(b, &r)305 if err == nil {306 o := HostServices(r)307 *pTypeDef = *((&o).Init())308 err = pTypeDef.Validate()309 }310 return err311}312//313// Validate - checks for missing required fields, etc314//315func (pTypeDef *HostServices) Validate() error {316 if pTypeDef.Host == "" {317 return fmt.Errorf("HostServices.host is missing but is a required field")318 } else {319 val := rdl.Validate(ZTSSchema(), "String", pTypeDef.Host)320 if !val.Valid {321 return fmt.Errorf("HostServices.host does not contain a valid String (%v)", val.Error)322 }323 }324 if pTypeDef.Names == nil {325 return fmt.Errorf("HostServices: Missing required field: names")326 }327 return nil328}329//330// AssertionEffect - Every assertion can have the effect of ALLOW or DENY.331//332type AssertionEffect int333//334// AssertionEffect constants335//336const (337 _ AssertionEffect = iota338 ALLOW339 DENY340)341var namesAssertionEffect = []string{342 ALLOW: "ALLOW",343 DENY: "DENY",344}345//346// NewAssertionEffect - return a string representation of the enum347//348func NewAssertionEffect(init ...interface{}) AssertionEffect {349 if len(init) == 1 {350 switch v := init[0].(type) {351 case AssertionEffect:352 return v353 case int:354 return AssertionEffect(v)355 case int32:356 return AssertionEffect(v)357 case string:358 for i, s := range namesAssertionEffect {359 if s == v {360 return AssertionEffect(i)361 }362 }363 default:364 panic("Bad init value for AssertionEffect enum")365 }366 }367 return AssertionEffect(0) //default to the first enum value368}369//370// String - return a string representation of the enum371//372func (e AssertionEffect) String() string {373 return namesAssertionEffect[e]374}375//376// SymbolSet - return an array of all valid string representations (symbols) of the enum377//378func (e AssertionEffect) SymbolSet() []string {379 return namesAssertionEffect380}381//382// MarshalJSON is defined for proper JSON encoding of a AssertionEffect383//384func (e AssertionEffect) MarshalJSON() ([]byte, error) {385 return json.Marshal(e.String())386}387//388// UnmarshalJSON is defined for proper JSON decoding of a AssertionEffect389//390func (e *AssertionEffect) UnmarshalJSON(b []byte) error {391 var j string392 err := json.Unmarshal(b, &j)393 if err == nil {394 s := string(j)395 for v, s2 := range namesAssertionEffect {396 if s == s2 {397 *e = AssertionEffect(v)398 return nil399 }400 }401 err = fmt.Errorf("Bad enum symbol for type AssertionEffect: %s", s)402 }403 return err404}405//406// Assertion - A representation for the encapsulation of an action to be407// performed on a resource by a principal.408//409type Assertion struct {410 //411 // the subject of the assertion, a role412 //413 Role string `json:"role"`414 //415 // the object of the assertion. Must be in the local namespace. Can contain416 // wildcards417 //418 Resource string `json:"resource"`419 //420 // the predicate of the assertion. Can contain wildcards421 //422 Action string `json:"action"`423 //424 // the effect of the assertion in the policy language425 //426 Effect *AssertionEffect `json:"effect,omitempty" rdl:"optional"`427 //428 // assertion id - auto generated by server429 //430 Id *int64 `json:"id,omitempty" rdl:"optional"`431}432//433// NewAssertion - creates an initialized Assertion instance, returns a pointer to it434//435func NewAssertion(init ...*Assertion) *Assertion {436 var o *Assertion437 if len(init) == 1 {438 o = init[0]439 } else {440 o = new(Assertion)441 }442 return o443}444type rawAssertion Assertion445//446// UnmarshalJSON is defined for proper JSON decoding of a Assertion447//448func (pTypeDef *Assertion) UnmarshalJSON(b []byte) error {449 var r rawAssertion450 err := json.Unmarshal(b, &r)451 if err == nil {452 o := Assertion(r)453 *pTypeDef = o454 err = pTypeDef.Validate()455 }456 return err457}458//459// Validate - checks for missing required fields, etc460//461func (pTypeDef *Assertion) Validate() error {462 if pTypeDef.Role == "" {463 return fmt.Errorf("Assertion.role is missing but is a required field")464 } else {465 val := rdl.Validate(ZTSSchema(), "String", pTypeDef.Role)466 if !val.Valid {467 return fmt.Errorf("Assertion.role does not contain a valid String (%v)", val.Error)468 }469 }470 if pTypeDef.Resource == "" {471 return fmt.Errorf("Assertion.resource is missing but is a required field")472 } else {473 val := rdl.Validate(ZTSSchema(), "String", pTypeDef.Resource)474 if !val.Valid {475 return fmt.Errorf("Assertion.resource does not contain a valid String (%v)", val.Error)476 }477 }478 if pTypeDef.Action == "" {479 return fmt.Errorf("Assertion.action is missing but is a required field")480 } else {481 val := rdl.Validate(ZTSSchema(), "String", pTypeDef.Action)482 if !val.Valid {483 return fmt.Errorf("Assertion.action does not contain a valid String (%v)", val.Error)484 }485 }486 return nil487}488//489// Policy - The representation for a Policy with set of assertions.490//491type Policy struct {492 //493 // name of the policy494 //495 Name ResourceName `json:"name"`496 //497 // last modification timestamp of this policy498 //499 Modified *rdl.Timestamp `json:"modified,omitempty" rdl:"optional"`500 //501 // list of defined assertions for this policy502 //503 Assertions []*Assertion `json:"assertions"`504}505//506// NewPolicy - creates an initialized Policy instance, returns a pointer to it507//508func NewPolicy(init ...*Policy) *Policy {509 var o *Policy510 if len(init) == 1 {511 o = init[0]512 } else {513 o = new(Policy)514 }515 return o.Init()516}517//518// Init - sets up the instance according to its default field values, if any519//520func (pTypeDef *Policy) Init() *Policy {521 if pTypeDef.Assertions == nil {522 pTypeDef.Assertions = make([]*Assertion, 0)523 }524 return pTypeDef525}526type rawPolicy Policy527//528// UnmarshalJSON is defined for proper JSON decoding of a Policy529//530func (pTypeDef *Policy) UnmarshalJSON(b []byte) error {531 var r rawPolicy532 err := json.Unmarshal(b, &r)533 if err == nil {534 o := Policy(r)535 *pTypeDef = *((&o).Init())536 err = pTypeDef.Validate()537 }538 return err539}540//541// Validate - checks for missing required fields, etc542//543func (pTypeDef *Policy) Validate() error {544 if pTypeDef.Name == "" {545 return fmt.Errorf("Policy.name is missing but is a required field")546 } else {547 val := rdl.Validate(ZTSSchema(), "ResourceName", pTypeDef.Name)548 if !val.Valid {549 return fmt.Errorf("Policy.name does not contain a valid ResourceName (%v)", val.Error)550 }551 }552 if pTypeDef.Assertions == nil {553 return fmt.Errorf("Policy: Missing required field: assertions")554 }555 return nil556}557//558// PolicyData -559//560type PolicyData struct {561 //562 // name of the domain563 //564 Domain DomainName `json:"domain"`565 //566 // list of policies defined in this server567 //568 Policies []*Policy `json:"policies"`569}570//571// NewPolicyData - creates an initialized PolicyData instance, returns a pointer to it572//573func NewPolicyData(init ...*PolicyData) *PolicyData {574 var o *PolicyData575 if len(init) == 1 {576 o = init[0]577 } else {578 o = new(PolicyData)579 }580 return o.Init()581}582//583// Init - sets up the instance according to its default field values, if any584//585func (pTypeDef *PolicyData) Init() *PolicyData {586 if pTypeDef.Policies == nil {587 pTypeDef.Policies = make([]*Policy, 0)588 }589 return pTypeDef590}591type rawPolicyData PolicyData592//593// UnmarshalJSON is defined for proper JSON decoding of a PolicyData594//595func (pTypeDef *PolicyData) UnmarshalJSON(b []byte) error {596 var r rawPolicyData597 err := json.Unmarshal(b, &r)598 if err == nil {599 o := PolicyData(r)600 *pTypeDef = *((&o).Init())601 err = pTypeDef.Validate()602 }603 return err604}605//606// Validate - checks for missing required fields, etc607//608func (pTypeDef *PolicyData) Validate() error {609 if pTypeDef.Domain == "" {610 return fmt.Errorf("PolicyData.domain is missing but is a required field")611 } else {612 val := rdl.Validate(ZTSSchema(), "DomainName", pTypeDef.Domain)613 if !val.Valid {614 return fmt.Errorf("PolicyData.domain does not contain a valid DomainName (%v)", val.Error)615 }616 }617 if pTypeDef.Policies == nil {618 return fmt.Errorf("PolicyData: Missing required field: policies")619 }620 return nil621}622//623// SignedPolicyData - A representation of policies object defined in a given624// server.625//626type SignedPolicyData struct {627 //628 // list of policies defined in a domain629 //630 PolicyData *PolicyData `json:"policyData"`631 //632 // zms signature generated based on the domain policies object633 //634 ZmsSignature string `json:"zmsSignature"`635 //636 // the identifier of the zms key used to generate the signature637 //638 ZmsKeyId string `json:"zmsKeyId"`639 //640 // when the domain itself was last modified641 //642 Modified rdl.Timestamp `json:"modified"`643 //644 // timestamp specifying the expiration time for using this set of policies645 //646 Expires rdl.Timestamp `json:"expires"`647}648//649// NewSignedPolicyData - creates an initialized SignedPolicyData instance, returns a pointer to it650//651func NewSignedPolicyData(init ...*SignedPolicyData) *SignedPolicyData {652 var o *SignedPolicyData653 if len(init) == 1 {654 o = init[0]655 } else {656 o = new(SignedPolicyData)657 }658 return o.Init()659}660//661// Init - sets up the instance according to its default field values, if any662//663func (pTypeDef *SignedPolicyData) Init() *SignedPolicyData {664 if pTypeDef.PolicyData == nil {665 pTypeDef.PolicyData = NewPolicyData()666 }667 return pTypeDef668}669type rawSignedPolicyData SignedPolicyData670//671// UnmarshalJSON is defined for proper JSON decoding of a SignedPolicyData672//673func (pTypeDef *SignedPolicyData) UnmarshalJSON(b []byte) error {674 var r rawSignedPolicyData675 err := json.Unmarshal(b, &r)676 if err == nil {677 o := SignedPolicyData(r)678 *pTypeDef = *((&o).Init())679 err = pTypeDef.Validate()680 }681 return err682}683//684// Validate - checks for missing required fields, etc685//686func (pTypeDef *SignedPolicyData) Validate() error {687 if pTypeDef.PolicyData == nil {688 return fmt.Errorf("SignedPolicyData: Missing required field: policyData")689 }690 if pTypeDef.ZmsSignature == "" {691 return fmt.Errorf("SignedPolicyData.zmsSignature is missing but is a required field")692 } else {693 val := rdl.Validate(ZTSSchema(), "String", pTypeDef.ZmsSignature)694 if !val.Valid {695 return fmt.Errorf("SignedPolicyData.zmsSignature does not contain a valid String (%v)", val.Error)696 }697 }698 if pTypeDef.ZmsKeyId == "" {699 return fmt.Errorf("SignedPolicyData.zmsKeyId is missing but is a required field")700 } else {701 val := rdl.Validate(ZTSSchema(), "String", pTypeDef.ZmsKeyId)702 if !val.Valid {703 return fmt.Errorf("SignedPolicyData.zmsKeyId does not contain a valid String (%v)", val.Error)704 }705 }706 if pTypeDef.Modified.IsZero() {707 return fmt.Errorf("SignedPolicyData: Missing required field: modified")708 }709 if pTypeDef.Expires.IsZero() {710 return fmt.Errorf("SignedPolicyData: Missing required field: expires")711 }712 return nil713}714//715// DomainSignedPolicyData - A signed bulk transfer of policies. The data is716// signed with server's private key.717//718type DomainSignedPolicyData struct {719 //720 // policy data signed by ZMS721 //722 SignedPolicyData *SignedPolicyData `json:"signedPolicyData"`723 //724 // signature generated based on the domain policies object725 //726 Signature string `json:"signature"`727 //728 // the identifier of the key used to generate the signature729 //730 KeyId string `json:"keyId"`731}732//733// NewDomainSignedPolicyData - creates an initialized DomainSignedPolicyData instance, returns a pointer to it734//735func NewDomainSignedPolicyData(init ...*DomainSignedPolicyData) *DomainSignedPolicyData {736 var o *DomainSignedPolicyData737 if len(init) == 1 {738 o = init[0]739 } else {740 o = new(DomainSignedPolicyData)741 }742 return o.Init()743}744//745// Init - sets up the instance according to its default field values, if any746//747func (pTypeDef *DomainSignedPolicyData) Init() *DomainSignedPolicyData {748 if pTypeDef.SignedPolicyData == nil {749 pTypeDef.SignedPolicyData = NewSignedPolicyData()750 }751 return pTypeDef752}753type rawDomainSignedPolicyData DomainSignedPolicyData754//755// UnmarshalJSON is defined for proper JSON decoding of a DomainSignedPolicyData756//757func (pTypeDef *DomainSignedPolicyData) UnmarshalJSON(b []byte) error {758 var r rawDomainSignedPolicyData759 err := json.Unmarshal(b, &r)760 if err == nil {761 o := DomainSignedPolicyData(r)762 *pTypeDef = *((&o).Init())763 err = pTypeDef.Validate()764 }765 return err766}767//768// Validate - checks for missing required fields, etc769//770func (pTypeDef *DomainSignedPolicyData) Validate() error {771 if pTypeDef.SignedPolicyData == nil {772 return fmt.Errorf("DomainSignedPolicyData: Missing required field: signedPolicyData")773 }774 if pTypeDef.Signature == "" {775 return fmt.Errorf("DomainSignedPolicyData.signature is missing but is a required field")776 } else {777 val := rdl.Validate(ZTSSchema(), "String", pTypeDef.Signature)778 if !val.Valid {779 return fmt.Errorf("DomainSignedPolicyData.signature does not contain a valid String (%v)", val.Error)780 }781 }782 if pTypeDef.KeyId == "" {783 return fmt.Errorf("DomainSignedPolicyData.keyId is missing but is a required field")784 } else {785 val := rdl.Validate(ZTSSchema(), "String", pTypeDef.KeyId)786 if !val.Valid {787 return fmt.Errorf("DomainSignedPolicyData.keyId does not contain a valid String (%v)", val.Error)788 }789 }790 return nil791}792//793// RoleToken - A representation of a signed RoleToken794//795type RoleToken struct {796 Token string `json:"token"`797 ExpiryTime int64 `json:"expiryTime"`798}799//800// NewRoleToken - creates an initialized RoleToken instance, returns a pointer to it801//802func NewRoleToken(init ...*RoleToken) *RoleToken {803 var o *RoleToken804 if len(init) == 1 {805 o = init[0]806 } else {807 o = new(RoleToken)808 }809 return o810}811type rawRoleToken RoleToken812//813// UnmarshalJSON is defined for proper JSON decoding of a RoleToken814//815func (pTypeDef *RoleToken) UnmarshalJSON(b []byte) error {816 var r rawRoleToken817 err := json.Unmarshal(b, &r)818 if err == nil {819 o := RoleToken(r)820 *pTypeDef = o821 err = pTypeDef.Validate()822 }823 return err824}825//826// Validate - checks for missing required fields, etc827//828func (pTypeDef *RoleToken) Validate() error {829 if pTypeDef.Token == "" {830 return fmt.Errorf("RoleToken.token is missing but is a required field")831 } else {832 val := rdl.Validate(ZTSSchema(), "String", pTypeDef.Token)833 if !val.Valid {834 return fmt.Errorf("RoleToken.token does not contain a valid String (%v)", val.Error)835 }836 }837 return nil838}839//840// RoleCertificateRequest - RoleCertificateRequest - a certificate signing841// request842//843type RoleCertificateRequest struct {844 Csr string `json:"csr"`845 ExpiryTime int64 `json:"expiryTime"`846}847//848// NewRoleCertificateRequest - creates an initialized RoleCertificateRequest instance, returns a pointer to it849//850func NewRoleCertificateRequest(init ...*RoleCertificateRequest) *RoleCertificateRequest {851 var o *RoleCertificateRequest852 if len(init) == 1 {853 o = init[0]854 } else {855 o = new(RoleCertificateRequest)856 }857 return o858}859type rawRoleCertificateRequest RoleCertificateRequest860//861// UnmarshalJSON is defined for proper JSON decoding of a RoleCertificateRequest862//863func (pTypeDef *RoleCertificateRequest) UnmarshalJSON(b []byte) error {864 var r rawRoleCertificateRequest865 err := json.Unmarshal(b, &r)866 if err == nil {867 o := RoleCertificateRequest(r)868 *pTypeDef = o869 err = pTypeDef.Validate()870 }871 return err872}873//874// Validate - checks for missing required fields, etc875//876func (pTypeDef *RoleCertificateRequest) Validate() error {877 if pTypeDef.Csr == "" {878 return fmt.Errorf("RoleCertificateRequest.csr is missing but is a required field")879 } else {880 val := rdl.Validate(ZTSSchema(), "String", pTypeDef.Csr)881 if !val.Valid {882 return fmt.Errorf("RoleCertificateRequest.csr does not contain a valid String (%v)", val.Error)883 }884 }885 return nil886}887//888// Access - Access can be checked and returned as this resource.889//890type Access struct {891 //892 // true (allowed) or false (denied)893 //894 Granted bool `json:"granted"`895}896//897// NewAccess - creates an initialized Access instance, returns a pointer to it898//899func NewAccess(init ...*Access) *Access {900 var o *Access901 if len(init) == 1 {902 o = init[0]903 } else {904 o = new(Access)905 }906 return o907}908type rawAccess Access909//910// UnmarshalJSON is defined for proper JSON decoding of a Access911//912func (pTypeDef *Access) UnmarshalJSON(b []byte) error {913 var r rawAccess914 err := json.Unmarshal(b, &r)915 if err == nil {916 o := Access(r)917 *pTypeDef = o918 err = pTypeDef.Validate()919 }920 return err921}922//923// Validate - checks for missing required fields, etc924//925func (pTypeDef *Access) Validate() error {926 return nil927}928//929// RoleAccess -930//931type RoleAccess struct {932 Roles []EntityName `json:"roles"`933}934//935// NewRoleAccess - creates an initialized RoleAccess instance, returns a pointer to it936//937func NewRoleAccess(init ...*RoleAccess) *RoleAccess {938 var o *RoleAccess939 if len(init) == 1 {940 o = init[0]941 } else {942 o = new(RoleAccess)943 }944 return o.Init()945}946//947// Init - sets up the instance according to its default field values, if any948//949func (pTypeDef *RoleAccess) Init() *RoleAccess {950 if pTypeDef.Roles == nil {951 pTypeDef.Roles = make([]EntityName, 0)952 }953 return pTypeDef954}955type rawRoleAccess RoleAccess956//957// UnmarshalJSON is defined for proper JSON decoding of a RoleAccess958//959func (pTypeDef *RoleAccess) UnmarshalJSON(b []byte) error {960 var r rawRoleAccess961 err := json.Unmarshal(b, &r)962 if err == nil {963 o := RoleAccess(r)964 *pTypeDef = *((&o).Init())965 err = pTypeDef.Validate()966 }967 return err968}969//970// Validate - checks for missing required fields, etc971//972func (pTypeDef *RoleAccess) Validate() error {973 if pTypeDef.Roles == nil {974 return fmt.Errorf("RoleAccess: Missing required field: roles")975 }976 return nil977}978//979// TenantDomains -980//981type TenantDomains struct {982 TenantDomainNames []DomainName `json:"tenantDomainNames"`983}984//985// NewTenantDomains - creates an initialized TenantDomains instance, returns a pointer to it986//987func NewTenantDomains(init ...*TenantDomains) *TenantDomains {988 var o *TenantDomains989 if len(init) == 1 {990 o = init[0]991 } else {992 o = new(TenantDomains)993 }994 return o.Init()995}996//997// Init - sets up the instance according to its default field values, if any998//999func (pTypeDef *TenantDomains) Init() *TenantDomains {1000 if pTypeDef.TenantDomainNames == nil {1001 pTypeDef.TenantDomainNames = make([]DomainName, 0)1002 }1003 return pTypeDef1004}1005type rawTenantDomains TenantDomains1006//1007// UnmarshalJSON is defined for proper JSON decoding of a TenantDomains1008//1009func (pTypeDef *TenantDomains) UnmarshalJSON(b []byte) error {1010 var r rawTenantDomains1011 err := json.Unmarshal(b, &r)1012 if err == nil {1013 o := TenantDomains(r)1014 *pTypeDef = *((&o).Init())1015 err = pTypeDef.Validate()1016 }1017 return err1018}1019//1020// Validate - checks for missing required fields, etc1021//1022func (pTypeDef *TenantDomains) Validate() error {1023 if pTypeDef.TenantDomainNames == nil {1024 return fmt.Errorf("TenantDomains: Missing required field: tenantDomainNames")1025 }1026 return nil1027}1028//1029// Identity - Identity - a signed assertion of service or human identity, the1030// response could be either a client certificate or just a regular NToken1031// (depending if the request contained a csr or not).1032//1033type Identity struct {1034 //1035 // name of the identity, fully qualified, i.e. my.domain.service1, or1036 // aws.1232321321312.myusername1037 //1038 Name CompoundName `json:"name"`1039 //1040 // a certificate usable for both client and server in TLS connections1041 //1042 Certificate string `json:"certificate,omitempty" rdl:"optional"`1043 //1044 // the CA certificate chain to use with all IMS-generated certs1045 //1046 CaCertBundle string `json:"caCertBundle,omitempty" rdl:"optional"`1047 //1048 // the SSH server cert, signed by the CA1049 //1050 SshServerCert string `json:"sshServerCert,omitempty" rdl:"optional"`1051 //1052 // service token instead of TLS certificate1053 //1054 ServiceToken SignedToken `json:"serviceToken,omitempty" rdl:"optional"`1055 //1056 // other config-like attributes determined at boot time1057 //1058 Attributes map[string]string `json:"attributes,omitempty" rdl:"optional"`1059}1060//1061// NewIdentity - creates an initialized Identity instance, returns a pointer to it1062//1063func NewIdentity(init ...*Identity) *Identity {1064 var o *Identity1065 if len(init) == 1 {1066 o = init[0]1067 } else {1068 o = new(Identity)1069 }1070 return o1071}1072type rawIdentity Identity1073//1074// UnmarshalJSON is defined for proper JSON decoding of a Identity1075//1076func (pTypeDef *Identity) UnmarshalJSON(b []byte) error {1077 var r rawIdentity1078 err := json.Unmarshal(b, &r)1079 if err == nil {1080 o := Identity(r)1081 *pTypeDef = o1082 err = pTypeDef.Validate()1083 }1084 return err1085}1086//1087// Validate - checks for missing required fields, etc1088//1089func (pTypeDef *Identity) Validate() error {1090 if pTypeDef.Name == "" {1091 return fmt.Errorf("Identity.name is missing but is a required field")1092 } else {1093 val := rdl.Validate(ZTSSchema(), "CompoundName", pTypeDef.Name)1094 if !val.Valid {1095 return fmt.Errorf("Identity.name does not contain a valid CompoundName (%v)", val.Error)1096 }1097 }1098 return nil1099}1100//1101// InstanceInformation - Instance object that includes requested service1102// details plus host document that is signed by provider as part of the host1103// bootstrap process1104//1105type InstanceInformation struct {1106 //1107 // signed document containing attributes like IP address, instance-id,1108 // account#, etc.1109 //1110 Document string `json:"document"`1111 //1112 // the signature for the document1113 //1114 Signature string `json:"signature"`1115 //1116 // the keyid used to sign the document1117 //1118 KeyId string `json:"keyId"`1119 //1120 // the domain of the instance1121 //1122 Domain CompoundName `json:"domain"`1123 //1124 // the service this instance is supposed to run1125 //1126 Service SimpleName `json:"service"`1127 //1128 // return a certificate in the response1129 //1130 Csr string `json:"csr"`1131}1132//1133// NewInstanceInformation - creates an initialized InstanceInformation instance, returns a pointer to it1134//1135func NewInstanceInformation(init ...*InstanceInformation) *InstanceInformation {1136 var o *InstanceInformation1137 if len(init) == 1 {1138 o = init[0]1139 } else {1140 o = new(InstanceInformation)1141 }1142 return o1143}1144type rawInstanceInformation InstanceInformation1145//1146// UnmarshalJSON is defined for proper JSON decoding of a InstanceInformation1147//1148func (pTypeDef *InstanceInformation) UnmarshalJSON(b []byte) error {1149 var r rawInstanceInformation1150 err := json.Unmarshal(b, &r)1151 if err == nil {1152 o := InstanceInformation(r)1153 *pTypeDef = o1154 err = pTypeDef.Validate()1155 }1156 return err1157}1158//1159// Validate - checks for missing required fields, etc1160//1161func (pTypeDef *InstanceInformation) Validate() error {1162 if pTypeDef.Document == "" {1163 return fmt.Errorf("InstanceInformation.document is missing but is a required field")1164 } else {1165 val := rdl.Validate(ZTSSchema(), "String", pTypeDef.Document)1166 if !val.Valid {1167 return fmt.Errorf("InstanceInformation.document does not contain a valid String (%v)", val.Error)1168 }1169 }1170 if pTypeDef.Signature == "" {1171 return fmt.Errorf("InstanceInformation.signature is missing but is a required field")1172 } else {1173 val := rdl.Validate(ZTSSchema(), "String", pTypeDef.Signature)1174 if !val.Valid {1175 return fmt.Errorf("InstanceInformation.signature does not contain a valid String (%v)", val.Error)1176 }1177 }1178 if pTypeDef.KeyId == "" {1179 return fmt.Errorf("InstanceInformation.keyId is missing but is a required field")1180 } else {1181 val := rdl.Validate(ZTSSchema(), "String", pTypeDef.KeyId)1182 if !val.Valid {1183 return fmt.Errorf("InstanceInformation.keyId does not contain a valid String (%v)", val.Error)1184 }1185 }1186 if pTypeDef.Domain == "" {1187 return fmt.Errorf("InstanceInformation.domain is missing but is a required field")1188 } else {1189 val := rdl.Validate(ZTSSchema(), "CompoundName", pTypeDef.Domain)1190 if !val.Valid {1191 return fmt.Errorf("InstanceInformation.domain does not contain a valid CompoundName (%v)", val.Error)1192 }1193 }1194 if pTypeDef.Service == "" {1195 return fmt.Errorf("InstanceInformation.service is missing but is a required field")1196 } else {1197 val := rdl.Validate(ZTSSchema(), "SimpleName", pTypeDef.Service)1198 if !val.Valid {1199 return fmt.Errorf("InstanceInformation.service does not contain a valid SimpleName (%v)", val.Error)1200 }1201 }1202 if pTypeDef.Csr == "" {1203 return fmt.Errorf("InstanceInformation.csr is missing but is a required field")1204 } else {1205 val := rdl.Validate(ZTSSchema(), "String", pTypeDef.Csr)1206 if !val.Valid {1207 return fmt.Errorf("InstanceInformation.csr does not contain a valid String (%v)", val.Error)1208 }1209 }1210 return nil1211}1212//1213// InstanceRefreshRequest - InstanceRefreshRequest - a certificate refresh1214// request1215//1216type InstanceRefreshRequest struct {1217 //1218 // Cert CSR if requesting TLS certificate1219 //1220 Csr string `json:"csr"`1221 //1222 // in seconds how long token should be valid for1223 //1224 ExpiryTime *int32 `json:"expiryTime,omitempty" rdl:"optional"`1225}1226//1227// NewInstanceRefreshRequest - creates an initialized InstanceRefreshRequest instance, returns a pointer to it1228//1229func NewInstanceRefreshRequest(init ...*InstanceRefreshRequest) *InstanceRefreshRequest {1230 var o *InstanceRefreshRequest1231 if len(init) == 1 {1232 o = init[0]1233 } else {1234 o = new(InstanceRefreshRequest)1235 }1236 return o1237}1238type rawInstanceRefreshRequest InstanceRefreshRequest1239//1240// UnmarshalJSON is defined for proper JSON decoding of a InstanceRefreshRequest1241//1242func (pTypeDef *InstanceRefreshRequest) UnmarshalJSON(b []byte) error {1243 var r rawInstanceRefreshRequest1244 err := json.Unmarshal(b, &r)1245 if err == nil {1246 o := InstanceRefreshRequest(r)1247 *pTypeDef = o1248 err = pTypeDef.Validate()1249 }1250 return err1251}1252//1253// Validate - checks for missing required fields, etc1254//1255func (pTypeDef *InstanceRefreshRequest) Validate() error {1256 if pTypeDef.Csr == "" {1257 return fmt.Errorf("InstanceRefreshRequest.csr is missing but is a required field")1258 } else {1259 val := rdl.Validate(ZTSSchema(), "String", pTypeDef.Csr)1260 if !val.Valid {1261 return fmt.Errorf("InstanceRefreshRequest.csr does not contain a valid String (%v)", val.Error)1262 }1263 }1264 return nil1265}1266//1267// AWSInstanceInformation - AWSInstanceInformation - the information a booting1268// EC2 instance must provide to ZTS to authenticate.1269//1270type AWSInstanceInformation struct {1271 //1272 // signed document containing attributes like IP address, instance-id,1273 // account#, etc.1274 //1275 Document string `json:"document"`1276 //1277 // the signature for the document1278 //1279 Signature string `json:"signature"`1280 //1281 // the domain of the instance1282 //1283 Domain CompoundName `json:"domain"`1284 //1285 // the service this instance is supposed to run1286 //1287 Service SimpleName `json:"service"`1288 //1289 // return a certificate in the response1290 //1291 Csr string `json:"csr"`1292 //1293 // the full service identity name (same as the EC2 instance profile name)1294 //1295 Name CompoundName `json:"name"`1296 //1297 // the account id (as a string) for the instance. parsed from the instance1298 // profile ARN1299 //1300 Account SimpleName `json:"account"`1301 //1302 // the name of the cloud (namespace) within the account, parsed from the name1303 //1304 Cloud SimpleName `json:"cloud,omitempty" rdl:"optional"`1305 //1306 // the name of the subnet this instance is expected to be running in, parsed1307 // from the name1308 //1309 Subnet SimpleName `json:"subnet"`1310 //1311 // the AWS Access Key Id for the role1312 //1313 Access string `json:"access"`1314 //1315 // the AWS Secret Access Key for the role1316 //1317 Secret string `json:"secret"`1318 //1319 // the AWS STS Token for the role1320 //1321 Token string `json:"token"`1322 //1323 // the expiration time of the access keys1324 //1325 Expires rdl.Timestamp `json:"expires"`1326 //1327 // the modified time of the access keys1328 //1329 Modified rdl.Timestamp `json:"modified"`1330 //1331 // the 'flavor' of the access keys, i.e. "AWS-HMAC"1332 //1333 Flavor string `json:"flavor"`1334}1335//1336// NewAWSInstanceInformation - creates an initialized AWSInstanceInformation instance, returns a pointer to it1337//1338func NewAWSInstanceInformation(init ...*AWSInstanceInformation) *AWSInstanceInformation {1339 var o *AWSInstanceInformation1340 if len(init) == 1 {1341 o = init[0]1342 } else {1343 o = new(AWSInstanceInformation)1344 }1345 return o1346}1347type rawAWSInstanceInformation AWSInstanceInformation1348//1349// UnmarshalJSON is defined for proper JSON decoding of a AWSInstanceInformation1350//1351func (pTypeDef *AWSInstanceInformation) UnmarshalJSON(b []byte) error {1352 var r rawAWSInstanceInformation1353 err := json.Unmarshal(b, &r)1354 if err == nil {1355 o := AWSInstanceInformation(r)1356 *pTypeDef = o1357 err = pTypeDef.Validate()1358 }1359 return err1360}1361//1362// Validate - checks for missing required fields, etc1363//1364func (pTypeDef *AWSInstanceInformation) Validate() error {1365 if pTypeDef.Document == "" {1366 return fmt.Errorf("AWSInstanceInformation.document is missing but is a required field")1367 } else {1368 val := rdl.Validate(ZTSSchema(), "String", pTypeDef.Document)1369 if !val.Valid {1370 return fmt.Errorf("AWSInstanceInformation.document does not contain a valid String (%v)", val.Error)1371 }1372 }1373 if pTypeDef.Signature == "" {1374 return fmt.Errorf("AWSInstanceInformation.signature is missing but is a required field")1375 } else {1376 val := rdl.Validate(ZTSSchema(), "String", pTypeDef.Signature)1377 if !val.Valid {1378 return fmt.Errorf("AWSInstanceInformation.signature does not contain a valid String (%v)", val.Error)1379 }1380 }1381 if pTypeDef.Domain == "" {1382 return fmt.Errorf("AWSInstanceInformation.domain is missing but is a required field")1383 } else {1384 val := rdl.Validate(ZTSSchema(), "CompoundName", pTypeDef.Domain)1385 if !val.Valid {1386 return fmt.Errorf("AWSInstanceInformation.domain does not contain a valid CompoundName (%v)", val.Error)1387 }1388 }1389 if pTypeDef.Service == "" {1390 return fmt.Errorf("AWSInstanceInformation.service is missing but is a required field")1391 } else {1392 val := rdl.Validate(ZTSSchema(), "SimpleName", pTypeDef.Service)1393 if !val.Valid {1394 return fmt.Errorf("AWSInstanceInformation.service does not contain a valid SimpleName (%v)", val.Error)1395 }1396 }1397 if pTypeDef.Csr == "" {1398 return fmt.Errorf("AWSInstanceInformation.csr is missing but is a required field")1399 } else {1400 val := rdl.Validate(ZTSSchema(), "String", pTypeDef.Csr)1401 if !val.Valid {1402 return fmt.Errorf("AWSInstanceInformation.csr does not contain a valid String (%v)", val.Error)1403 }1404 }1405 if pTypeDef.Name == "" {1406 return fmt.Errorf("AWSInstanceInformation.name is missing but is a required field")1407 } else {1408 val := rdl.Validate(ZTSSchema(), "CompoundName", pTypeDef.Name)1409 if !val.Valid {1410 return fmt.Errorf("AWSInstanceInformation.name does not contain a valid CompoundName (%v)", val.Error)1411 }1412 }1413 if pTypeDef.Account == "" {1414 return fmt.Errorf("AWSInstanceInformation.account is missing but is a required field")1415 } else {1416 val := rdl.Validate(ZTSSchema(), "SimpleName", pTypeDef.Account)1417 if !val.Valid {1418 return fmt.Errorf("AWSInstanceInformation.account does not contain a valid SimpleName (%v)", val.Error)1419 }1420 }1421 if pTypeDef.Subnet == "" {1422 return fmt.Errorf("AWSInstanceInformation.subnet is missing but is a required field")1423 } else {1424 val := rdl.Validate(ZTSSchema(), "SimpleName", pTypeDef.Subnet)1425 if !val.Valid {1426 return fmt.Errorf("AWSInstanceInformation.subnet does not contain a valid SimpleName (%v)", val.Error)1427 }1428 }1429 if pTypeDef.Access == "" {1430 return fmt.Errorf("AWSInstanceInformation.access is missing but is a required field")1431 } else {1432 val := rdl.Validate(ZTSSchema(), "String", pTypeDef.Access)1433 if !val.Valid {1434 return fmt.Errorf("AWSInstanceInformation.access does not contain a valid String (%v)", val.Error)1435 }1436 }1437 if pTypeDef.Secret == "" {1438 return fmt.Errorf("AWSInstanceInformation.secret is missing but is a required field")1439 } else {1440 val := rdl.Validate(ZTSSchema(), "String", pTypeDef.Secret)1441 if !val.Valid {1442 return fmt.Errorf("AWSInstanceInformation.secret does not contain a valid String (%v)", val.Error)1443 }1444 }1445 if pTypeDef.Token == "" {1446 return fmt.Errorf("AWSInstanceInformation.token is missing but is a required field")1447 } else {1448 val := rdl.Validate(ZTSSchema(), "String", pTypeDef.Token)1449 if !val.Valid {1450 return fmt.Errorf("AWSInstanceInformation.token does not contain a valid String (%v)", val.Error)1451 }1452 }1453 if pTypeDef.Expires.IsZero() {1454 return fmt.Errorf("AWSInstanceInformation: Missing required field: expires")1455 }1456 if pTypeDef.Modified.IsZero() {1457 return fmt.Errorf("AWSInstanceInformation: Missing required field: modified")1458 }1459 if pTypeDef.Flavor == "" {1460 return fmt.Errorf("AWSInstanceInformation.flavor is missing but is a required field")1461 } else {1462 val := rdl.Validate(ZTSSchema(), "String", pTypeDef.Flavor)1463 if !val.Valid {1464 return fmt.Errorf("AWSInstanceInformation.flavor does not contain a valid String (%v)", val.Error)1465 }1466 }1467 return nil1468}1469//1470// AWSCertificateRequest - AWSCertificateRequest - a certificate signing1471// request1472//1473type AWSCertificateRequest struct {1474 Csr string `json:"csr"`1475}1476//1477// NewAWSCertificateRequest - creates an initialized AWSCertificateRequest instance, returns a pointer to it1478//1479func NewAWSCertificateRequest(init ...*AWSCertificateRequest) *AWSCertificateRequest {1480 var o *AWSCertificateRequest1481 if len(init) == 1 {1482 o = init[0]1483 } else {1484 o = new(AWSCertificateRequest)1485 }1486 return o1487}1488type rawAWSCertificateRequest AWSCertificateRequest1489//1490// UnmarshalJSON is defined for proper JSON decoding of a AWSCertificateRequest1491//1492func (pTypeDef *AWSCertificateRequest) UnmarshalJSON(b []byte) error {1493 var r rawAWSCertificateRequest1494 err := json.Unmarshal(b, &r)1495 if err == nil {1496 o := AWSCertificateRequest(r)1497 *pTypeDef = o1498 err = pTypeDef.Validate()1499 }1500 return err1501}1502//1503// Validate - checks for missing required fields, etc1504//1505func (pTypeDef *AWSCertificateRequest) Validate() error {1506 if pTypeDef.Csr == "" {1507 return fmt.Errorf("AWSCertificateRequest.csr is missing but is a required field")1508 } else {1509 val := rdl.Validate(ZTSSchema(), "String", pTypeDef.Csr)1510 if !val.Valid {1511 return fmt.Errorf("AWSCertificateRequest.csr does not contain a valid String (%v)", val.Error)1512 }1513 }1514 return nil1515}1516//1517// AWSTemporaryCredentials -1518//1519type AWSTemporaryCredentials struct {1520 AccessKeyId string `json:"accessKeyId"`1521 SecretAccessKey string `json:"secretAccessKey"`1522 SessionToken string `json:"sessionToken"`1523 Expiration rdl.Timestamp `json:"expiration"`1524}1525//1526// NewAWSTemporaryCredentials - creates an initialized AWSTemporaryCredentials instance, returns a pointer to it1527//1528func NewAWSTemporaryCredentials(init ...*AWSTemporaryCredentials) *AWSTemporaryCredentials {1529 var o *AWSTemporaryCredentials1530 if len(init) == 1 {1531 o = init[0]1532 } else {1533 o = new(AWSTemporaryCredentials)1534 }1535 return o1536}1537type rawAWSTemporaryCredentials AWSTemporaryCredentials1538//1539// UnmarshalJSON is defined for proper JSON decoding of a AWSTemporaryCredentials1540//1541func (pTypeDef *AWSTemporaryCredentials) UnmarshalJSON(b []byte) error {1542 var r rawAWSTemporaryCredentials1543 err := json.Unmarshal(b, &r)1544 if err == nil {1545 o := AWSTemporaryCredentials(r)1546 *pTypeDef = o1547 err = pTypeDef.Validate()1548 }1549 return err1550}1551//1552// Validate - checks for missing required fields, etc1553//1554func (pTypeDef *AWSTemporaryCredentials) Validate() error {1555 if pTypeDef.AccessKeyId == "" {1556 return fmt.Errorf("AWSTemporaryCredentials.accessKeyId is missing but is a required field")1557 } else {1558 val := rdl.Validate(ZTSSchema(), "String", pTypeDef.AccessKeyId)1559 if !val.Valid {1560 return fmt.Errorf("AWSTemporaryCredentials.accessKeyId does not contain a valid String (%v)", val.Error)1561 }1562 }1563 if pTypeDef.SecretAccessKey == "" {1564 return fmt.Errorf("AWSTemporaryCredentials.secretAccessKey is missing but is a required field")1565 } else {1566 val := rdl.Validate(ZTSSchema(), "String", pTypeDef.SecretAccessKey)1567 if !val.Valid {1568 return fmt.Errorf("AWSTemporaryCredentials.secretAccessKey does not contain a valid String (%v)", val.Error)1569 }1570 }1571 if pTypeDef.SessionToken == "" {1572 return fmt.Errorf("AWSTemporaryCredentials.sessionToken is missing but is a required field")1573 } else {1574 val := rdl.Validate(ZTSSchema(), "String", pTypeDef.SessionToken)1575 if !val.Valid {1576 return fmt.Errorf("AWSTemporaryCredentials.sessionToken does not contain a valid String (%v)", val.Error)1577 }1578 }1579 if pTypeDef.Expiration.IsZero() {1580 return fmt.Errorf("AWSTemporaryCredentials: Missing required field: expiration")1581 }1582 return nil1583}1584//1585// DomainMetricType - zpe metric attributes1586//1587type DomainMetricType int1588//1589// DomainMetricType constants1590//1591const (1592 _ DomainMetricType = iota1593 ACCESS_ALLOWED1594 ACCESS_ALLOWED_DENY1595 ACCESS_ALLOWED_DENY_NO_MATCH1596 ACCESS_ALLOWED_ALLOW1597 ACCESS_ALLOWED_ERROR1598 ACCESS_ALLOWED_TOKEN_INVALID1599 ACCESS_Allowed_TOKEN_EXPIRED1600 ACCESS_ALLOWED_DOMAIN_NOT_FOUND1601 ACCESS_ALLOWED_DOMAIN_MISMATCH1602 ACCESS_ALLOWED_DOMAIN_EXPIRED1603 ACCESS_ALLOWED_DOMAIN_EMPTY1604 ACCESS_ALLOWED_TOKEN_CACHE_FAILURE1605 ACCESS_ALLOWED_TOKEN_CACHE_NOT_FOUND1606 ACCESS_ALLOWED_TOKEN_CACHE_SUCCESS1607 ACCESS_ALLOWED_TOKEN_VALIDATE1608 LOAD_FILE_FAIL1609 LOAD_FILE_GOOD1610 LOAD_DOMAIN_GOOD1611)1612var namesDomainMetricType = []string{1613 ACCESS_ALLOWED: "ACCESS_ALLOWED",1614 ACCESS_ALLOWED_DENY: "ACCESS_ALLOWED_DENY",1615 ACCESS_ALLOWED_DENY_NO_MATCH: "ACCESS_ALLOWED_DENY_NO_MATCH",1616 ACCESS_ALLOWED_ALLOW: "ACCESS_ALLOWED_ALLOW",1617 ACCESS_ALLOWED_ERROR: "ACCESS_ALLOWED_ERROR",1618 ACCESS_ALLOWED_TOKEN_INVALID: "ACCESS_ALLOWED_TOKEN_INVALID",1619 ACCESS_Allowed_TOKEN_EXPIRED: "ACCESS_Allowed_TOKEN_EXPIRED",1620 ACCESS_ALLOWED_DOMAIN_NOT_FOUND: "ACCESS_ALLOWED_DOMAIN_NOT_FOUND",1621 ACCESS_ALLOWED_DOMAIN_MISMATCH: "ACCESS_ALLOWED_DOMAIN_MISMATCH",1622 ACCESS_ALLOWED_DOMAIN_EXPIRED: "ACCESS_ALLOWED_DOMAIN_EXPIRED",1623 ACCESS_ALLOWED_DOMAIN_EMPTY: "ACCESS_ALLOWED_DOMAIN_EMPTY",1624 ACCESS_ALLOWED_TOKEN_CACHE_FAILURE: "ACCESS_ALLOWED_TOKEN_CACHE_FAILURE",1625 ACCESS_ALLOWED_TOKEN_CACHE_NOT_FOUND: "ACCESS_ALLOWED_TOKEN_CACHE_NOT_FOUND",1626 ACCESS_ALLOWED_TOKEN_CACHE_SUCCESS: "ACCESS_ALLOWED_TOKEN_CACHE_SUCCESS",1627 ACCESS_ALLOWED_TOKEN_VALIDATE: "ACCESS_ALLOWED_TOKEN_VALIDATE",1628 LOAD_FILE_FAIL: "LOAD_FILE_FAIL",1629 LOAD_FILE_GOOD: "LOAD_FILE_GOOD",1630 LOAD_DOMAIN_GOOD: "LOAD_DOMAIN_GOOD",1631}1632//1633// NewDomainMetricType - return a string representation of the enum1634//1635func NewDomainMetricType(init ...interface{}) DomainMetricType {1636 if len(init) == 1 {1637 switch v := init[0].(type) {1638 case DomainMetricType:1639 return v1640 case int:1641 return DomainMetricType(v)1642 case int32:1643 return DomainMetricType(v)1644 case string:1645 for i, s := range namesDomainMetricType {1646 if s == v {1647 return DomainMetricType(i)1648 }1649 }1650 default:1651 panic("Bad init value for DomainMetricType enum")1652 }1653 }1654 return DomainMetricType(0) //default to the first enum value1655}1656//1657// String - return a string representation of the enum1658//1659func (e DomainMetricType) String() string {1660 return namesDomainMetricType[e]1661}1662//1663// SymbolSet - return an array of all valid string representations (symbols) of the enum1664//1665func (e DomainMetricType) SymbolSet() []string {1666 return namesDomainMetricType1667}1668//1669// MarshalJSON is defined for proper JSON encoding of a DomainMetricType1670//1671func (e DomainMetricType) MarshalJSON() ([]byte, error) {1672 return json.Marshal(e.String())1673}1674//1675// UnmarshalJSON is defined for proper JSON decoding of a DomainMetricType1676//1677func (e *DomainMetricType) UnmarshalJSON(b []byte) error {1678 var j string1679 err := json.Unmarshal(b, &j)1680 if err == nil {1681 s := string(j)1682 for v, s2 := range namesDomainMetricType {1683 if s == s2 {1684 *e = DomainMetricType(v)1685 return nil1686 }1687 }1688 err = fmt.Errorf("Bad enum symbol for type DomainMetricType: %s", s)1689 }1690 return err1691}1692//1693// DomainMetric -1694//1695type DomainMetric struct {1696 MetricType DomainMetricType `json:"metricType"`1697 MetricVal int32 `json:"metricVal"`1698}1699//1700// NewDomainMetric - creates an initialized DomainMetric instance, returns a pointer to it1701//1702func NewDomainMetric(init ...*DomainMetric) *DomainMetric {1703 var o *DomainMetric1704 if len(init) == 1 {1705 o = init[0]1706 } else {1707 o = new(DomainMetric)1708 }1709 return o1710}1711type rawDomainMetric DomainMetric1712//1713// UnmarshalJSON is defined for proper JSON decoding of a DomainMetric1714//1715func (pTypeDef *DomainMetric) UnmarshalJSON(b []byte) error {1716 var r rawDomainMetric1717 err := json.Unmarshal(b, &r)1718 if err == nil {1719 o := DomainMetric(r)1720 *pTypeDef = o1721 err = pTypeDef.Validate()1722 }1723 return err1724}1725//1726// Validate - checks for missing required fields, etc1727//1728func (pTypeDef *DomainMetric) Validate() error {1729 return nil1730}1731//1732// DomainMetrics -1733//1734type DomainMetrics struct {1735 //1736 // name of the domain the metrics pertain to1737 //1738 DomainName DomainName `json:"domainName"`1739 //1740 // list of the domains metrics1741 //1742 MetricList []*DomainMetric `json:"metricList"`1743}1744//1745// NewDomainMetrics - creates an initialized DomainMetrics instance, returns a pointer to it1746//1747func NewDomainMetrics(init ...*DomainMetrics) *DomainMetrics {1748 var o *DomainMetrics1749 if len(init) == 1 {1750 o = init[0]1751 } else {1752 o = new(DomainMetrics)1753 }1754 return o.Init()1755}1756//1757// Init - sets up the instance according to its default field values, if any1758//1759func (pTypeDef *DomainMetrics) Init() *DomainMetrics {1760 if pTypeDef.MetricList == nil {1761 pTypeDef.MetricList = make([]*DomainMetric, 0)1762 }1763 return pTypeDef1764}1765type rawDomainMetrics DomainMetrics1766//1767// UnmarshalJSON is defined for proper JSON decoding of a DomainMetrics1768//1769func (pTypeDef *DomainMetrics) UnmarshalJSON(b []byte) error {1770 var r rawDomainMetrics1771 err := json.Unmarshal(b, &r)1772 if err == nil {1773 o := DomainMetrics(r)1774 *pTypeDef = *((&o).Init())1775 err = pTypeDef.Validate()1776 }1777 return err1778}1779//1780// Validate - checks for missing required fields, etc1781//1782func (pTypeDef *DomainMetrics) Validate() error {1783 if pTypeDef.DomainName == "" {...

Full Screen

Full Screen

search_aggs.go

Source:search_aggs.go Github

copy

Full Screen

...428type AggregationValueMetric struct {429 Aggregations430 Value *float64 //`json:"value"`431}432// UnmarshalJSON decodes JSON data and initializes an AggregationValueMetric structure.433func (a *AggregationValueMetric) UnmarshalJSON(data []byte) error {434 var aggs map[string]*json.RawMessage435 if err := json.Unmarshal(data, &aggs); err != nil {436 return err437 }438 if v, ok := aggs["value"]; ok && v != nil {439 json.Unmarshal(*v, &a.Value)440 }441 a.Aggregations = aggs442 return nil443}444// -- Stats metric --445// AggregationStatsMetric is a multi-value metric, returned by a Stats aggregation.446type AggregationStatsMetric struct {447 Aggregations448 Count int64 // `json:"count"`449 Min *float64 //`json:"min,omitempty"`450 Max *float64 //`json:"max,omitempty"`451 Avg *float64 //`json:"avg,omitempty"`452 Sum *float64 //`json:"sum,omitempty"`453}454// UnmarshalJSON decodes JSON data and initializes an AggregationStatsMetric structure.455func (a *AggregationStatsMetric) UnmarshalJSON(data []byte) error {456 var aggs map[string]*json.RawMessage457 if err := json.Unmarshal(data, &aggs); err != nil {458 return err459 }460 if v, ok := aggs["count"]; ok && v != nil {461 json.Unmarshal(*v, &a.Count)462 }463 if v, ok := aggs["min"]; ok && v != nil {464 json.Unmarshal(*v, &a.Min)465 }466 if v, ok := aggs["max"]; ok && v != nil {467 json.Unmarshal(*v, &a.Max)468 }469 if v, ok := aggs["avg"]; ok && v != nil {470 json.Unmarshal(*v, &a.Avg)471 }472 if v, ok := aggs["sum"]; ok && v != nil {473 json.Unmarshal(*v, &a.Sum)474 }475 a.Aggregations = aggs476 return nil477}478// -- Extended stats metric --479// AggregationExtendedStatsMetric is a multi-value metric, returned by an ExtendedStats aggregation.480type AggregationExtendedStatsMetric struct {481 Aggregations482 Count int64 // `json:"count"`483 Min *float64 //`json:"min,omitempty"`484 Max *float64 //`json:"max,omitempty"`485 Avg *float64 //`json:"avg,omitempty"`486 Sum *float64 //`json:"sum,omitempty"`487 SumOfSquares *float64 //`json:"sum_of_squares,omitempty"`488 Variance *float64 //`json:"variance,omitempty"`489 StdDeviation *float64 //`json:"std_deviation,omitempty"`490}491// UnmarshalJSON decodes JSON data and initializes an AggregationExtendedStatsMetric structure.492func (a *AggregationExtendedStatsMetric) UnmarshalJSON(data []byte) error {493 var aggs map[string]*json.RawMessage494 if err := json.Unmarshal(data, &aggs); err != nil {495 return err496 }497 if v, ok := aggs["count"]; ok && v != nil {498 json.Unmarshal(*v, &a.Count)499 }500 if v, ok := aggs["min"]; ok && v != nil {501 json.Unmarshal(*v, &a.Min)502 }503 if v, ok := aggs["max"]; ok && v != nil {504 json.Unmarshal(*v, &a.Max)505 }506 if v, ok := aggs["avg"]; ok && v != nil {507 json.Unmarshal(*v, &a.Avg)508 }509 if v, ok := aggs["sum"]; ok && v != nil {510 json.Unmarshal(*v, &a.Sum)511 }512 if v, ok := aggs["sum_of_squares"]; ok && v != nil {513 json.Unmarshal(*v, &a.SumOfSquares)514 }515 if v, ok := aggs["variance"]; ok && v != nil {516 json.Unmarshal(*v, &a.Variance)517 }518 if v, ok := aggs["std_deviation"]; ok && v != nil {519 json.Unmarshal(*v, &a.StdDeviation)520 }521 a.Aggregations = aggs522 return nil523}524// -- Percentiles metric --525// AggregationPercentilesMetric is a multi-value metric, returned by a Percentiles aggregation.526type AggregationPercentilesMetric struct {527 Aggregations528 Values map[string]float64 // `json:"values"`529}530// UnmarshalJSON decodes JSON data and initializes an AggregationPercentilesMetric structure.531func (a *AggregationPercentilesMetric) UnmarshalJSON(data []byte) error {532 var aggs map[string]*json.RawMessage533 if err := json.Unmarshal(data, &aggs); err != nil {534 return err535 }536 if v, ok := aggs["values"]; ok && v != nil {537 json.Unmarshal(*v, &a.Values)538 }539 a.Aggregations = aggs540 return nil541}542// -- Top-hits metric --543// AggregationTopHitsMetric is a metric returned by a TopHits aggregation.544type AggregationTopHitsMetric struct {545 Aggregations546 Hits *SearchHits //`json:"hits"`547}548// UnmarshalJSON decodes JSON data and initializes an AggregationTopHitsMetric structure.549func (a *AggregationTopHitsMetric) UnmarshalJSON(data []byte) error {550 var aggs map[string]*json.RawMessage551 if err := json.Unmarshal(data, &aggs); err != nil {552 return err553 }554 a.Aggregations = aggs555 a.Hits = new(SearchHits)556 if v, ok := aggs["hits"]; ok && v != nil {557 json.Unmarshal(*v, &a.Hits)558 }559 return nil560}561// -- Geo-bounds metric --562// AggregationGeoBoundsMetric is a metric as returned by a GeoBounds aggregation.563type AggregationGeoBoundsMetric struct {564 Aggregations565 Bounds struct {566 TopLeft struct {567 Latitude float64 `json:"lat"`568 Longitude float64 `json:"lon"`569 } `json:"top_left"`570 BottomRight struct {571 Latitude float64 `json:"lat"`572 Longitude float64 `json:"lon"`573 } `json:"bottom_right"`574 } `json:"bounds"`575}576// UnmarshalJSON decodes JSON data and initializes an AggregationGeoBoundsMetric structure.577func (a *AggregationGeoBoundsMetric) UnmarshalJSON(data []byte) error {578 var aggs map[string]*json.RawMessage579 if err := json.Unmarshal(data, &aggs); err != nil {580 return err581 }582 if v, ok := aggs["bounds"]; ok && v != nil {583 json.Unmarshal(*v, &a.Bounds)584 }585 a.Aggregations = aggs586 return nil587}588// -- Single bucket --589// AggregationSingleBucket is a single bucket, returned e.g. via an aggregation of type Global.590type AggregationSingleBucket struct {591 Aggregations592 DocCount int64 // `json:"doc_count"`593}594// UnmarshalJSON decodes JSON data and initializes an AggregationSingleBucket structure.595func (a *AggregationSingleBucket) UnmarshalJSON(data []byte) error {596 var aggs map[string]*json.RawMessage597 if err := json.Unmarshal(data, &aggs); err != nil {598 return err599 }600 if v, ok := aggs["doc_count"]; ok && v != nil {601 json.Unmarshal(*v, &a.DocCount)602 }603 a.Aggregations = aggs604 return nil605}606// -- Bucket range items --607// AggregationBucketRangeItems is a bucket aggregation that is e.g. returned608// with a range aggregation.609type AggregationBucketRangeItems struct {610 Aggregations611 DocCountErrorUpperBound int64 //`json:"doc_count_error_upper_bound"`612 SumOfOtherDocCount int64 //`json:"sum_other_doc_count"`613 Buckets []*AggregationBucketRangeItem //`json:"buckets"`614}615// UnmarshalJSON decodes JSON data and initializes an AggregationBucketRangeItems structure.616func (a *AggregationBucketRangeItems) UnmarshalJSON(data []byte) error {617 var aggs map[string]*json.RawMessage618 if err := json.Unmarshal(data, &aggs); err != nil {619 return err620 }621 if v, ok := aggs["doc_count_error_upper_bound"]; ok && v != nil {622 json.Unmarshal(*v, &a.DocCountErrorUpperBound)623 }624 if v, ok := aggs["sum_other_doc_count"]; ok && v != nil {625 json.Unmarshal(*v, &a.SumOfOtherDocCount)626 }627 if v, ok := aggs["buckets"]; ok && v != nil {628 json.Unmarshal(*v, &a.Buckets)629 }630 a.Aggregations = aggs631 return nil632}633// AggregationBucketKeyedRangeItems is a bucket aggregation that is e.g. returned634// with a keyed range aggregation.635type AggregationBucketKeyedRangeItems struct {636 Aggregations637 DocCountErrorUpperBound int64 //`json:"doc_count_error_upper_bound"`638 SumOfOtherDocCount int64 //`json:"sum_other_doc_count"`639 Buckets map[string]*AggregationBucketRangeItem //`json:"buckets"`640}641// UnmarshalJSON decodes JSON data and initializes an AggregationBucketRangeItems structure.642func (a *AggregationBucketKeyedRangeItems) UnmarshalJSON(data []byte) error {643 var aggs map[string]*json.RawMessage644 if err := json.Unmarshal(data, &aggs); err != nil {645 return err646 }647 if v, ok := aggs["doc_count_error_upper_bound"]; ok && v != nil {648 json.Unmarshal(*v, &a.DocCountErrorUpperBound)649 }650 if v, ok := aggs["sum_other_doc_count"]; ok && v != nil {651 json.Unmarshal(*v, &a.SumOfOtherDocCount)652 }653 if v, ok := aggs["buckets"]; ok && v != nil {654 json.Unmarshal(*v, &a.Buckets)655 }656 a.Aggregations = aggs657 return nil658}659// AggregationBucketRangeItem is a single bucket of an AggregationBucketRangeItems structure.660type AggregationBucketRangeItem struct {661 Aggregations662 Key string //`json:"key"`663 DocCount int64 //`json:"doc_count"`664 From *float64 //`json:"from"`665 FromAsString string //`json:"from_as_string"`666 To *float64 //`json:"to"`667 ToAsString string //`json:"to_as_string"`668}669// UnmarshalJSON decodes JSON data and initializes an AggregationBucketRangeItem structure.670func (a *AggregationBucketRangeItem) UnmarshalJSON(data []byte) error {671 var aggs map[string]*json.RawMessage672 if err := json.Unmarshal(data, &aggs); err != nil {673 return err674 }675 if v, ok := aggs["key"]; ok && v != nil {676 json.Unmarshal(*v, &a.Key)677 }678 if v, ok := aggs["doc_count"]; ok && v != nil {679 json.Unmarshal(*v, &a.DocCount)680 }681 if v, ok := aggs["from"]; ok && v != nil {682 json.Unmarshal(*v, &a.From)683 }684 if v, ok := aggs["from_as_string"]; ok && v != nil {685 json.Unmarshal(*v, &a.FromAsString)686 }687 if v, ok := aggs["to"]; ok && v != nil {688 json.Unmarshal(*v, &a.To)689 }690 if v, ok := aggs["to_as_string"]; ok && v != nil {691 json.Unmarshal(*v, &a.ToAsString)692 }693 a.Aggregations = aggs694 return nil695}696// -- Bucket key items --697// AggregationBucketKeyItems is a bucket aggregation that is e.g. returned698// with a terms aggregation.699type AggregationBucketKeyItems struct {700 Aggregations701 DocCountErrorUpperBound int64 //`json:"doc_count_error_upper_bound"`702 SumOfOtherDocCount int64 //`json:"sum_other_doc_count"`703 Buckets []*AggregationBucketKeyItem //`json:"buckets"`704}705// UnmarshalJSON decodes JSON data and initializes an AggregationBucketKeyItems structure.706func (a *AggregationBucketKeyItems) UnmarshalJSON(data []byte) error {707 var aggs map[string]*json.RawMessage708 if err := json.Unmarshal(data, &aggs); err != nil {709 return err710 }711 if v, ok := aggs["doc_count_error_upper_bound"]; ok && v != nil {712 json.Unmarshal(*v, &a.DocCountErrorUpperBound)713 }714 if v, ok := aggs["sum_other_doc_count"]; ok && v != nil {715 json.Unmarshal(*v, &a.SumOfOtherDocCount)716 }717 if v, ok := aggs["buckets"]; ok && v != nil {718 json.Unmarshal(*v, &a.Buckets)719 }720 a.Aggregations = aggs721 return nil722}723// AggregationBucketKeyItem is a single bucket of an AggregationBucketKeyItems structure.724type AggregationBucketKeyItem struct {725 Aggregations726 Key interface{} //`json:"key"`727 KeyNumber json.Number728 DocCount int64 //`json:"doc_count"`729}730// UnmarshalJSON decodes JSON data and initializes an AggregationBucketKeyItem structure.731func (a *AggregationBucketKeyItem) UnmarshalJSON(data []byte) error {732 var aggs map[string]*json.RawMessage733 dec := json.NewDecoder(bytes.NewReader(data))734 dec.UseNumber()735 if err := dec.Decode(&aggs); err != nil {736 return err737 }738 if v, ok := aggs["key"]; ok && v != nil {739 json.Unmarshal(*v, &a.Key)740 json.Unmarshal(*v, &a.KeyNumber)741 }742 if v, ok := aggs["doc_count"]; ok && v != nil {743 json.Unmarshal(*v, &a.DocCount)744 }745 a.Aggregations = aggs746 return nil747}748// -- Bucket types for significant terms --749// AggregationBucketSignificantTerms is a bucket aggregation returned750// with a significant terms aggregation.751type AggregationBucketSignificantTerms struct {752 Aggregations753 DocCount int64 //`json:"doc_count"`754 Buckets []*AggregationBucketSignificantTerm //`json:"buckets"`755}756// UnmarshalJSON decodes JSON data and initializes an AggregationBucketSignificantTerms structure.757func (a *AggregationBucketSignificantTerms) UnmarshalJSON(data []byte) error {758 var aggs map[string]*json.RawMessage759 if err := json.Unmarshal(data, &aggs); err != nil {760 return err761 }762 if v, ok := aggs["doc_count"]; ok && v != nil {763 json.Unmarshal(*v, &a.DocCount)764 }765 if v, ok := aggs["buckets"]; ok && v != nil {766 json.Unmarshal(*v, &a.Buckets)767 }768 a.Aggregations = aggs769 return nil770}771// AggregationBucketSignificantTerm is a single bucket of an AggregationBucketSignificantTerms structure.772type AggregationBucketSignificantTerm struct {773 Aggregations774 Key string //`json:"key"`775 DocCount int64 //`json:"doc_count"`776 BgCount int64 //`json:"bg_count"`777 Score float64 //`json:"score"`778}779// UnmarshalJSON decodes JSON data and initializes an AggregationBucketSignificantTerm structure.780func (a *AggregationBucketSignificantTerm) UnmarshalJSON(data []byte) error {781 var aggs map[string]*json.RawMessage782 if err := json.Unmarshal(data, &aggs); err != nil {783 return err784 }785 if v, ok := aggs["key"]; ok && v != nil {786 json.Unmarshal(*v, &a.Key)787 }788 if v, ok := aggs["doc_count"]; ok && v != nil {789 json.Unmarshal(*v, &a.DocCount)790 }791 if v, ok := aggs["bg_count"]; ok && v != nil {792 json.Unmarshal(*v, &a.BgCount)793 }794 if v, ok := aggs["score"]; ok && v != nil {795 json.Unmarshal(*v, &a.Score)796 }797 a.Aggregations = aggs798 return nil799}800// -- Bucket filters --801// AggregationBucketFilters is a multi-bucket aggregation that is returned802// with a filters aggregation.803type AggregationBucketFilters struct {804 Aggregations805 Buckets []*AggregationBucketKeyItem //`json:"buckets"`806 NamedBuckets map[string]*AggregationBucketKeyItem //`json:"buckets"`807}808// UnmarshalJSON decodes JSON data and initializes an AggregationBucketFilters structure.809func (a *AggregationBucketFilters) UnmarshalJSON(data []byte) error {810 var aggs map[string]*json.RawMessage811 if err := json.Unmarshal(data, &aggs); err != nil {812 return err813 }814 if v, ok := aggs["buckets"]; ok && v != nil {815 json.Unmarshal(*v, &a.Buckets)816 json.Unmarshal(*v, &a.NamedBuckets)817 }818 a.Aggregations = aggs819 return nil820}821// -- Bucket histogram items --822// AggregationBucketHistogramItems is a bucket aggregation that is returned823// with a date histogram aggregation.824type AggregationBucketHistogramItems struct {825 Aggregations826 Buckets []*AggregationBucketHistogramItem //`json:"buckets"`827}828// UnmarshalJSON decodes JSON data and initializes an AggregationBucketHistogramItems structure.829func (a *AggregationBucketHistogramItems) UnmarshalJSON(data []byte) error {830 var aggs map[string]*json.RawMessage831 if err := json.Unmarshal(data, &aggs); err != nil {832 return err833 }834 if v, ok := aggs["buckets"]; ok && v != nil {835 json.Unmarshal(*v, &a.Buckets)836 }837 a.Aggregations = aggs838 return nil839}840// AggregationBucketHistogramItem is a single bucket of an AggregationBucketHistogramItems structure.841type AggregationBucketHistogramItem struct {842 Aggregations843 Key int64 //`json:"key"`844 KeyAsString *string //`json:"key_as_string"`845 DocCount int64 //`json:"doc_count"`846}847// UnmarshalJSON decodes JSON data and initializes an AggregationBucketHistogramItem structure.848func (a *AggregationBucketHistogramItem) UnmarshalJSON(data []byte) error {849 var aggs map[string]*json.RawMessage850 if err := json.Unmarshal(data, &aggs); err != nil {851 return err852 }853 if v, ok := aggs["key"]; ok && v != nil {854 json.Unmarshal(*v, &a.Key)855 }856 if v, ok := aggs["key_as_string"]; ok && v != nil {857 json.Unmarshal(*v, &a.KeyAsString)858 }859 if v, ok := aggs["doc_count"]; ok && v != nil {860 json.Unmarshal(*v, &a.DocCount)861 }862 a.Aggregations = aggs...

Full Screen

Full Screen

emf.go

Source:emf.go Github

copy

Full Screen

...8type emf struct {9 // AWS corresponds to the JSON schema field "_aws".10 AWS emfAWS `json:"_aws"`11}12// UnmarshalJSON implements json.Unmarshaler.13func (j *emfAWSCloudWatchMetricsElemMetricsElem) UnmarshalJSON(b []byte) error {14 var raw map[string]interface{}15 if err := json.Unmarshal(b, &raw); err != nil {16 return err17 }18 if v, ok := raw["Name"]; !ok || v == nil {19 return fmt.Errorf("field Name: required")20 }21 if v, ok := raw["Unit"]; !ok || v == nil {22 return fmt.Errorf("field Unit: required")23 }24 type Plain emfAWSCloudWatchMetricsElemMetricsElem25 var plain Plain26 if err := json.Unmarshal(b, &plain); err != nil {27 return err28 }29 *j = emfAWSCloudWatchMetricsElemMetricsElem(plain)30 return nil31}32type emfAWSCloudWatchMetricsElem struct {33 // Dimensions corresponds to the JSON schema field "Dimensions".34 Dimensions [][]string `json:"Dimensions"`35 // Metrics corresponds to the JSON schema field "Metrics".36 Metrics []emfAWSCloudWatchMetricsElemMetricsElem `json:"Metrics"`37 // Namespace corresponds to the JSON schema field "Namespace".38 Namespace string `json:"Namespace"`39}40// UnmarshalJSON implements json.Unmarshaler.41func (j *emfAWSCloudWatchMetricsElem) UnmarshalJSON(b []byte) error {42 var raw map[string]interface{}43 if err := json.Unmarshal(b, &raw); err != nil {44 return err45 }46 if v, ok := raw["Dimensions"]; !ok || v == nil {47 return fmt.Errorf("field Dimensions: required")48 }49 if v, ok := raw["Metrics"]; !ok || v == nil {50 return fmt.Errorf("field Metrics: required")51 }52 if v, ok := raw["Namespace"]; !ok || v == nil {53 return fmt.Errorf("field Namespace: required")54 }55 type Plain emfAWSCloudWatchMetricsElem56 var plain Plain57 if err := json.Unmarshal(b, &plain); err != nil {58 return err59 }60 *j = emfAWSCloudWatchMetricsElem(plain)61 return nil62}63type emfAWS struct {64 // CloudWatchMetrics corresponds to the JSON schema field "CloudWatchMetrics".65 CloudWatchMetrics []emfAWSCloudWatchMetricsElem `json:"CloudWatchMetrics"`66 // Timestamp corresponds to the JSON schema field "Timestamp".67 Timestamp int `json:"Timestamp"`68}69// UnmarshalJSON implements json.Unmarshaler.70func (j *emfAWS) UnmarshalJSON(b []byte) error {71 var raw map[string]interface{}72 if err := json.Unmarshal(b, &raw); err != nil {73 return err74 }75 if v, ok := raw["CloudWatchMetrics"]; !ok || v == nil {76 return fmt.Errorf("field CloudWatchMetrics: required")77 }78 if v, ok := raw["Timestamp"]; !ok || v == nil {79 return fmt.Errorf("field Timestamp: required")80 }81 type Plain emfAWS82 var plain Plain83 if err := json.Unmarshal(b, &plain); err != nil {84 return err85 }86 *j = emfAWS(plain)87 return nil88}89type emfAWSCloudWatchMetricsElemMetricsElem struct {90 // Name corresponds to the JSON schema field "Name".91 Name string `json:"Name"`92 // Unit corresponds to the JSON schema field "Unit".93 Unit string `json:"Unit"`94}95// UnmarshalJSON implements json.Unmarshaler.96func (j *emf) UnmarshalJSON(b []byte) error {97 var raw map[string]interface{}98 if err := json.Unmarshal(b, &raw); err != nil {99 return err100 }101 if v, ok := raw["_aws"]; !ok || v == nil {102 return fmt.Errorf("field _aws: required")103 }104 //lint:ignore U1000 because it's actually used105 type Plain emf106 var plain Plain107 if err := json.Unmarshal(b, &plain); err != nil {108 return err109 }110 *j = emf(plain)...

Full Screen

Full Screen

UnmarshalJSON

Using AI Code Generation

copy

Full Screen

1import (2type Metrics struct {3}4type Metric struct {5}6func main() {7 data := []byte(`{"metrics":[{"name":"cpu","value":"0.5"},{"name":"memory","value":"0.5"}]}`)8 err := json.Unmarshal(data, &metrics)9 if err != nil {10 fmt.Println("error:", err)11 }12 fmt.Println(metrics)13}14[{cpu 0.5} {memory 0.5}]15import (16type Metrics struct {17}18type Metric struct {19}20func (m Metrics) MarshalJSON() ([]byte, error) {21 return json.Marshal(m.Metrics)22}23func main() {24 metrics := Metrics{25 Metrics: []Metric{26 Metric{27 },28 Metric{29 },30 },31 }32 data, err := json.Marshal(metrics)33 if err != nil {34 fmt.Println("error:", err)35 }36 fmt.Println(string(data))37}38[{"name":"cpu","value":"0.5"},{"name":"memory","value":"0.5"}]

Full Screen

Full Screen

UnmarshalJSON

Using AI Code Generation

copy

Full Screen

1import (2type Metrics struct {3}4func (m *Metrics) UnmarshalJSON(b []byte) error {5 var tmp interface{}6 err := json.Unmarshal(b, &tmp)7 if err != nil {8 }9 switch tmp.(type) {10 m.Name = tmp.(string)11 case map[string]interface{}:12 m.Name = tmp.(map[string]interface{})["name"].(string)13 m.Value = tmp.(map[string]interface{})["value"].(string)14 return fmt.Errorf("unknown type")15 }16}17func main() {18 data := []byte(`[{"name":"foo","value":"bar"},{"name":"foo","value":"bar"}]`)19 err := json.Unmarshal(data, &metrics)20 if err != nil {21 fmt.Println(err)22 }23 fmt.Println(metrics)24}25[{foo bar} {foo bar}]

Full Screen

Full Screen

UnmarshalJSON

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 b := []byte(`{"data":{"id":"1","type":"metrics","attributes":{"name":"foo","value":"bar"}}}`)4 err := json.Unmarshal(b, &m)5 if err != nil {6 fmt.Println("error:", err)7 }8 fmt.Printf("%+v9}10import (11func main() {12 b := []byte(`{"data":{"id":"1","type":"metrics","attributes":{"name":"foo","value":"bar"}}}`)13 err := json.Unmarshal(b, &m)14 if err != nil {15 fmt.Println("error:", err)16 }17 fmt.Printf("%+v18}19import (20func main() {21 b := []byte(`{"data":{"id":"1","type":"metrics","attributes":{"name":"foo","value":"bar"}}}`)22 err := json.Unmarshal(b, &m)23 if err != nil {24 fmt.Println("error:", err)25 }26 fmt.Printf("%+v27}28import (29func main() {30 b := []byte(`{"data":{"id":"1","type":"metrics","attributes":{"name":"foo","value":"bar"}}}`)31 err := json.Unmarshal(b, &m)32 if err != nil {33 fmt.Println("error:", err)34 }35 fmt.Printf("%+v36}37import (38func main() {39 b := []byte(`{"data":{"id":"1","type":"metrics","attributes":{"name":"foo","value":"bar"}}}`)40 err := json.Unmarshal(b, &m)

Full Screen

Full Screen

UnmarshalJSON

Using AI Code Generation

copy

Full Screen

1func main() {2}3func main() {4}5func main() {6}7func main() {8}9func main() {10}11func main() {12}13func main() {14}15func main() {16}17func main() {18}19func main() {20}21func main() {

Full Screen

Full Screen

UnmarshalJSON

Using AI Code Generation

copy

Full Screen

1func main() {2 err := json.Unmarshal([]byte(`{3 "address": {4 },5 }`), &m)6 if err != nil {7 fmt.Println(err)8 }9 fmt.Println(m)10}

Full Screen

Full Screen

UnmarshalJSON

Using AI Code Generation

copy

Full Screen

1func main() {2 m := metrics{}3 json := `{"name":"cpu","values":{"user":10,"system":20}}`4 err := json.Unmarshal([]byte(json), &m)5 if err != nil {6 fmt.Println(err)7 }8 fmt.Println(m)9}10{cpu map[system:20 user:10]}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run K6 automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful