sacloud / libsacloud

[Deprecated] Library for SAKURA Cloud API with Go
Apache License 2.0
18 stars 13 forks source link

service: 価格表(ServiceClass)の表示が煩雑 #656

Closed yamamoto-febc closed 2 years ago

yamamoto-febc commented 3 years ago

related #550

service/serviceclass(価格表)のPriceをうまく表示する方法が欲しい。

現在は以下のように定義されている。

// ServiceClass represents API parameter/response structure
type ServiceClass struct {
    ID               types.ID
    ServiceClassName string
    ServiceClassPath string
    DisplayName      string
    IsPublic         bool
    Price            *Price `mapconv:",recursive"`
}

// Price represents API parameter/response structure
type Price struct {
    Base          int
    Daily         int
    Hourly        int
    Monthly       int
    PerUse        int
    Basic         int
    Traffic       int
    DocomoTraffic int
    KddiTraffic   int
    SbTraffic     int
    SimSheet      int
    Zone          string
}

Priceのどの項目が価格を表しているのかがそれぞれによって異なるため、利用者側で適切なPriceのフィールドを選ばないといけない。

yamamoto-febc commented 3 years ago

参考: usacloudでは以下のように表示している。

func userFriendlyPriceString(value interface{}) string {
    if value == nil {
        return ""
    }
    v, ok := value.(*sacloud.Price)
    if !ok {
        return ""
    }

    var results []string

    if v.Base > 0 {
        results = append(results, fmt.Sprintf("Base:%d", v.Base))
    }
    if v.Daily > 0 {
        results = append(results, fmt.Sprintf("Daily:%d", v.Daily))
    }
    if v.Hourly > 0 {
        results = append(results, fmt.Sprintf("Hourly:%d", v.Hourly))
    }
    if v.Monthly > 0 {
        results = append(results, fmt.Sprintf("Monthly:%d", v.Monthly))
    }
    if v.PerUse > 0 {
        results = append(results, fmt.Sprintf("PerUse:%d", v.PerUse))
    }
    if v.Basic > 0 {
        results = append(results, fmt.Sprintf("Basic:%d", v.Basic))
    }
    if v.Traffic > 0 {
        results = append(results, fmt.Sprintf("Traffic:%d", v.Traffic))
    }
    if v.DocomoTraffic > 0 {
        results = append(results, fmt.Sprintf("DocomoTraffic:%d", v.DocomoTraffic))
    }
    if v.KddiTraffic > 0 {
        results = append(results, fmt.Sprintf("KddiTraffic:%d", v.KddiTraffic))
    }
    if v.SbTraffic > 0 {
        results = append(results, fmt.Sprintf("SbTraffic:%d", v.SbTraffic))
    }
    if v.SimSheet > 0 {
        results = append(results, fmt.Sprintf("SimSheet:%d", v.SimSheet))
    }
    if v.Zone != "" {
        results = append(results, fmt.Sprintf("Zone:%s", v.Zone))
    }

    return strings.Join(results, " / ")
}
yamamoto-febc commented 2 years ago

iaas-api-goの移行に伴いクローズ。必要であればiaas-api-go側で別途オープンする。