File: deprecation.go

package info (click to toggle)
golang-github-hetznercloud-hcloud-go 2.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,072 kB
  • sloc: sh: 5; makefile: 2
file content (59 lines) | stat: -rw-r--r-- 2,106 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package hcloud

import "time"

// Deprecatable is a shared interface implemented by all Resources that have a defined deprecation workflow.
type Deprecatable interface {
	// IsDeprecated returns true if the resource is marked as deprecated.
	IsDeprecated() bool

	// UnavailableAfter returns the time that the deprecated resource will be removed from the API.
	// This only returns a valid value if [Deprecatable.IsDeprecated] returned true.
	UnavailableAfter() time.Time

	// DeprecationAnnounced returns the time that the deprecation of this resource was announced.
	// This only returns a valid value if [Deprecatable.IsDeprecated] returned true.
	DeprecationAnnounced() time.Time
}

// DeprecationInfo contains the information published when a resource is actually deprecated.
type DeprecationInfo struct {
	Announced        time.Time
	UnavailableAfter time.Time
}

// DeprecatableResource implements the [Deprecatable] interface and can be embedded in structs for Resources that can be
// deprecated.
type DeprecatableResource struct {
	Deprecation *DeprecationInfo
}

// IsDeprecated returns true if the resource is marked as deprecated.
func (d DeprecatableResource) IsDeprecated() bool {
	return d.Deprecation != nil
}

// UnavailableAfter returns the time that the deprecated resource will be removed from the API.
// This only returns a valid value if [Deprecatable.IsDeprecated] returned true.
func (d DeprecatableResource) UnavailableAfter() time.Time {
	if !d.IsDeprecated() {
		// Return "null" time if resource is not deprecated
		return time.Unix(0, 0)
	}

	return d.Deprecation.UnavailableAfter
}

// DeprecationAnnounced returns the time that the deprecation of this resource was announced.
// This only returns a valid value if [Deprecatable.IsDeprecated] returned true.
func (d DeprecatableResource) DeprecationAnnounced() time.Time {
	if !d.IsDeprecated() {
		// Return "null" time if resource is not deprecated
		return time.Unix(0, 0)
	}

	return d.Deprecation.Announced
}

// Make sure that all expected Resources actually implement the interface.
var _ Deprecatable = ServerType{}