github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/pkg/platform/api/mono/mono.go (about) 1 package mono 2 3 import ( 4 "net/http" 5 "net/url" 6 7 "github.com/go-openapi/runtime" 8 httptransport "github.com/go-openapi/runtime/client" 9 "github.com/go-openapi/strfmt" 10 11 "github.com/ActiveState/cli/pkg/platform/api" 12 "github.com/ActiveState/cli/pkg/platform/api/mono/mono_client" 13 ) 14 15 // persist contains the active API Client connection 16 var persist *mono_client.Mono 17 18 // New will create a new API client using default settings (for an authenticated version use the NewWithAuth version) 19 func New() *mono_client.Mono { 20 return Init(api.GetServiceURL(api.ServiceMono), nil) 21 } 22 23 // NewWithAuth creates a new API client using default settings and the provided authentication info 24 func NewWithAuth(auth *runtime.ClientAuthInfoWriter) *mono_client.Mono { 25 return Init(api.GetServiceURL(api.ServiceMono), auth) 26 } 27 28 // Init initializes a new api client 29 func Init(serviceURL *url.URL, auth *runtime.ClientAuthInfoWriter) *mono_client.Mono { 30 transportRuntime := httptransport.New(serviceURL.Host, serviceURL.Path, []string{serviceURL.Scheme}) 31 transportRuntime.Transport = api.NewRoundTripper(http.DefaultTransport) 32 33 // transportRuntime.SetDebug(true) 34 35 if auth != nil { 36 transportRuntime.DefaultAuthentication = *auth 37 } 38 return mono_client.New(transportRuntime, strfmt.Default) 39 } 40 41 // Get returns a cached version of the default api client 42 func Get() *mono_client.Mono { 43 if persist == nil { 44 persist = New() 45 } 46 return persist 47 }