betas.go raw

   1  package linodego
   2  
   3  import (
   4  	"context"
   5  	"encoding/json"
   6  	"time"
   7  
   8  	"github.com/linode/linodego/internal/parseabletime"
   9  )
  10  
  11  // BetaProgram is a new product or service that is not generally available to all Akamai customers.
  12  // Users must enroll into a beta in order to access the functionality.
  13  type BetaProgram struct {
  14  	Label       string `json:"label"`
  15  	ID          string `json:"id"`
  16  	Description string `json:"description"`
  17  
  18  	// Start date of the beta program.
  19  	Started *time.Time `json:"-"`
  20  
  21  	// End date of the beta program.
  22  	Ended *time.Time `json:"-"`
  23  
  24  	// Greenlight is a program that allows customers to gain access to
  25  	// certain beta programs and to collect direct feedback from those customers.
  26  	GreenlightOnly bool `json:"greenlight_only"`
  27  
  28  	// Link to product marketing page for the beta program.
  29  	MoreInfo string `json:"more_info"`
  30  }
  31  
  32  // UnmarshalJSON implements the json.Unmarshaler interface
  33  func (beta *BetaProgram) UnmarshalJSON(b []byte) error {
  34  	type Mask BetaProgram
  35  
  36  	p := struct {
  37  		*Mask
  38  
  39  		Started *parseabletime.ParseableTime `json:"started"`
  40  		Ended   *parseabletime.ParseableTime `json:"ended"`
  41  	}{
  42  		Mask: (*Mask)(beta),
  43  	}
  44  
  45  	if err := json.Unmarshal(b, &p); err != nil {
  46  		return err
  47  	}
  48  
  49  	beta.Started = (*time.Time)(p.Started)
  50  	beta.Ended = (*time.Time)(p.Ended)
  51  
  52  	return nil
  53  }
  54  
  55  // ListBetaPrograms lists active beta programs
  56  func (c *Client) ListBetaPrograms(ctx context.Context, opts *ListOptions) ([]BetaProgram, error) {
  57  	return getPaginatedResults[BetaProgram](ctx, c, "/betas", opts)
  58  }
  59  
  60  // GetBetaProgram gets the beta program's detail with the ID
  61  func (c *Client) GetBetaProgram(ctx context.Context, betaID string) (*BetaProgram, error) {
  62  	e := formatAPIPath("betas/%s", betaID)
  63  	return doGETRequest[BetaProgram](ctx, c, e)
  64  }
  65