Я заинтересован в использовании библиотеки github.com/mosen/vpp
для взаимодействия с API-интерфейсами программы закупок Apple (VPP). Для начала я искал метод GetLicenses()
(ср. https://github.com/mosen/vpp/blob/eb451c2d433e9548c025737cf8b4fcef5c1f5b80/licenses.go#L58 -L83 ), который читает
type getLicensesRequestOpts struct {
AssignedOnly bool `json:"assignedOnly,omitempty"`
AdamID int `json:"adamId,omitempty"`
PricingParam PricingParam `json:"pricingParam,omitempty"`
}
// GetLicensesOption describes the signature of the closure returned by a function adding an argument to GetLicenses
type GetLicensesOption func(*getLicensesRequestOpts) error
// GetLicenses retrieves a list of available VPP licenses. The result can optionally be filtered by the application id
// and/or its assigned status.
func (s *licensesService) GetLicenses(batch *BatchRequest, opts ...GetLicensesOption) ([]VPPLicense, error) {
requestOpts := &getLicensesRequestOpts{}
for _, option := range opts {
if err := option(requestOpts); err != nil {
return nil, err
}
}
var request *getVPPLicensesSrvRequest = &getVPPLicensesSrvRequest{
getLicensesRequestOpts: requestOpts,
SToken: s.sToken,
BatchRequest: batch,
}
var response getVPPLicensesSrvResponse
req, err := s.client.NewRequest("POST", s.client.Config.serviceConfig.GetLicensesSrvURL, request)
if err != nil {
return nil, err
}
err = s.client.Do(req, &response)
if err != nil {
return nil, err
}
if response.Status == StatusErr {
return nil, response.VPPError
}
return response.Licenses, nil
}
Эта экспортированная функция нигде не вызывается в этом проекте, так что кажется, что следует использовать его напрямую, но я не уверен, как, учитывая, что getLicensesRequestOpts
является частным. Я хотел бы определить GetLicensesOption
как
func assignedOnlyOption(opts *vpp.getLicensesRequestOpts) error {
opts.AssignedOnly = true
return nil
}
и затем вызвать метод как
vpp.NewService("my sToken").GetLicenses(&vpp.BatchRequest{}, assignedOnlyOption)
Однако я не верю, что смогу определить такую опцию, если getLicensesRequestOpts
является частным, если я не добавлю его в эту библиотеку.
Короче говоря, я не понимаю, как пользователи должны использовать этот метод?