dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts@v1.0.2/models/intervalaction.go (about)

     1  //
     2  // Copyright (C) 2021 IOTech Ltd
     3  //
     4  // SPDX-License-Identifier: Apache-2.0
     5  
     6  package models
     7  
     8  import (
     9  	"encoding/json"
    10  
    11  	"dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts/errors"
    12  )
    13  
    14  // AuthMethod controls the authentication method to be applied to outbound http requests for interval actions
    15  type AuthMethod string
    16  
    17  type IntervalAction struct {
    18  	DBTimestamp
    19  	Id           string
    20  	Name         string
    21  	IntervalName string
    22  	Content      string
    23  	ContentType  string
    24  	Address      Address
    25  	AdminState   AdminState
    26  	AuthMethod   AuthMethod
    27  }
    28  
    29  func (intervalAction *IntervalAction) UnmarshalJSON(b []byte) error {
    30  	var alias struct {
    31  		DBTimestamp
    32  		Id           string
    33  		Name         string
    34  		IntervalName string
    35  		Content      string
    36  		ContentType  string
    37  		Address      interface{}
    38  		AdminState   AdminState
    39  		AuthMethod   AuthMethod
    40  	}
    41  	if err := json.Unmarshal(b, &alias); err != nil {
    42  		return errors.NewCommonEdgeX(errors.KindContractInvalid, "Failed to unmarshal intervalAction.", err)
    43  	}
    44  	address, err := instantiateAddress(alias.Address)
    45  	if err != nil {
    46  		return errors.NewCommonEdgeXWrapper(err)
    47  	}
    48  
    49  	*intervalAction = IntervalAction{
    50  		DBTimestamp:  alias.DBTimestamp,
    51  		Id:           alias.Id,
    52  		Name:         alias.Name,
    53  		IntervalName: alias.IntervalName,
    54  		Content:      alias.Content,
    55  		ContentType:  alias.ContentType,
    56  		Address:      address,
    57  		AdminState:   alias.AdminState,
    58  		AuthMethod:   alias.AuthMethod,
    59  	}
    60  	return nil
    61  }