Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new APIs for traffic pricings [release-1.x] #496

Merged
merged 4 commits into from
Jul 25, 2024

Conversation

apricote
Copy link
Member

The API has been updated to provide a better insight and more flexibility for displaying the pricing of traffic for servers and load balancers.

In addition to the new fields, the old fields are deprecated and will be set to null in the API on 2024-08-05.

As far as we could tell they are not widely used in Open Source code, please check if you are using them in any private code. Some linters automatically check for deprecated fields, if you use golangci-lint this is provided by the staticcheck linter.

You can learn more about this change in our changelog.

Upgrading

Server Type Included Traffic

If you were using the field hcloud.ServerType.IncludedTraffic, you can now get the information through hcloud.ServerType.Pricings:

func main() {
    // previous
    includedTraffic := serverType.IncludedTraffic

    // now
    locationOfInterest := "fsn1"
    var includedTraffic uint64
    for _, price := range serverType.Pricings {
        if price.Location.Name == locationOfInterest {
            includedTraffic = price.IncludedTraffic
            break
        }
    }
}

Traffic Prices

If you were using the field hcloud.Pricing.Traffic, you can now get the information through hcloud.Pricing.ServerTypes or hcloud.Pricing.LoadBalancerTypes:

func main() {
    // previous
    trafficPrice := pricing.Traffic

    // now
    serverTypeOfInterest := "cx22"
    locationOfInterest := "fsn1"

    var trafficPrice hcloud.Price
    for _, serverTypePricings := range pricing.ServerTypes {
        if serverTypePricings.ServerType.Name == serverTypeOfInterest {
            for _, price := range serverTypePricings {
               if price.Location.Name == locationOfInterest {
                   trafficPrice = price.PerTBTraffic
                   break
               }
            }
        }
    }
}

release-please Info

BEGIN_COMMIT_OVERRIDE
feat(server-type): new traffic price fields
feat(load-balancer-type): new traffic price fields
feat(pricing): mark traffic field as deprecated
feat(server-type): mark included traffic field as deprecated
END_COMMIT_OVERRIDE

@apricote apricote requested a review from a team as a code owner July 25, 2024 11:08
@apricote apricote self-assigned this Jul 25, 2024
@apricote apricote requested a review from jooola July 25, 2024 11:09
@apricote apricote changed the base branch from main to release-1.x July 25, 2024 11:09
@apricote apricote merged commit 90c3110 into release-1.x Jul 25, 2024
1 check passed
@apricote apricote deleted the traffic-apis-v1 branch July 25, 2024 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants