github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/release/update/protocol.go (about)

     1  // Copyright 2015 Keybase, Inc. All rights reserved. Use of
     2  // this source code is governed by the included BSD license.
     3  
     4  package update
     5  
     6  import "time"
     7  
     8  // Asset describes a downloadable file.
     9  type Asset struct {
    10  	Name      string `codec:"name" json:"name"`
    11  	URL       string `codec:"url" json:"url"`
    12  	Digest    string `codec:"digest" json:"digest"`
    13  	Signature string `codec:"signature" json:"signature"`
    14  	LocalPath string `codec:"localPath" json:"localPath"`
    15  }
    16  
    17  // Type is the type of update
    18  type Type int
    19  
    20  const (
    21  	// Normal is a normal update
    22  	Normal Type = 0
    23  	// Bugfix is a bugfix
    24  	Bugfix Type = 1
    25  	// Critical is critical
    26  	Critical Type = 2
    27  )
    28  
    29  // Property is a generic key value pair for custom properties
    30  type Property struct {
    31  	Name  string `codec:"name" json:"name"`
    32  	Value string `codec:"value" json:"value"`
    33  }
    34  
    35  // Update defines an update
    36  type Update struct {
    37  	Version      string     `codec:"version" json:"version"`
    38  	Name         string     `codec:"name" json:"name"`
    39  	Description  string     `codec:"description" json:"description"`
    40  	Instructions *string    `codec:"instructions,omitempty" json:"instructions,omitempty"`
    41  	Type         Type       `codec:"type" json:"type"`
    42  	PublishedAt  *Time      `codec:"publishedAt,omitempty" json:"publishedAt,omitempty"`
    43  	Props        []Property `codec:"props" json:"props,omitempty"`
    44  	Asset        *Asset     `codec:"asset,omitempty" json:"asset,omitempty"`
    45  }
    46  
    47  // Time as millis
    48  type Time int64
    49  
    50  // FromTime converts millis to Time
    51  func FromTime(t Time) time.Time {
    52  	if t == 0 {
    53  		return time.Time{}
    54  	}
    55  	return time.Unix(0, int64(t)*1000000)
    56  }
    57  
    58  // ToTime converts Time to millis
    59  func ToTime(t time.Time) Time {
    60  	// the result of calling UnixNano on the zero Time is undefined.
    61  	// https://golang.org/pkg/time/#Time.UnixNano
    62  	if t.IsZero() {
    63  		return 0
    64  	}
    65  	return Time(t.UnixNano() / 1000000)
    66  }