@@ -11,26 +11,43 @@ import (
1111type Client struct {
1212 client * goprsc.Client
1313
14+ Auth * AuthService
1415 Domains * DomainService
1516 Accounts * AccountService
1617 Aliases * AliasService
1718 InputBccs * InputBccService
1819 OutputBccs * OutputBccService
1920}
2021
22+ // GetLogin returns the user login associated with the client
23+ func (c * Client ) GetLogin () string {
24+ return c .client .Login
25+ }
26+
27+ // GetAuthToken returns the authentication token associated with the client
28+ func (c * Client ) GetAuthToken () string {
29+ return c .client .AuthToken
30+ }
31+
32+ // GetRefreshToken returns the refresh token associated with the client
33+ func (c * Client ) GetRefreshToken () string {
34+ return c .client .RefreshToken
35+ }
36+
2137type service struct {
2238 client * goprsc.Client
2339}
2440
2541// NewClient creates an instance of Client.
2642func NewClient () (* Client , error ) {
27- goprscClient , err := getGoprscClient ()
43+ goprscClient , err := newGoprscClient ()
2844 if err != nil {
2945 return nil , fmt .Errorf ("unable to initialize Postfix REST Server API client: %s" , err )
3046 }
3147
3248 c := & Client {client : goprscClient }
3349 s := service {client : goprscClient } // Reuse the same structure instead of allocating one for each service
50+ c .Auth = (* AuthService )(& s )
3451 c .Domains = (* DomainService )(& s )
3552 c .Accounts = (* AccountService )(& s )
3653 c .Aliases = (* AliasService )(& s )
@@ -40,17 +57,25 @@ func NewClient() (*Client, error) {
4057 return c , nil
4158}
4259
43- func getGoprscClient () (* goprsc.Client , error ) {
60+ func newGoprscClient () (* goprsc.Client , error ) {
4461 host := viper .GetString ("host" )
4562 port := viper .GetString ("port" )
4663 useHTTPS := viper .GetBool ("https" )
4764
65+ login := viper .GetString ("login" )
66+ authToken := viper .GetString ("authToken" )
67+ refreshToken := viper .GetString ("refreshToken" )
68+
4869 var options []goprsc.ClientOption
70+ options = append (options , goprsc .UserAgentOption ("emailctl" ))
4971 options = append (options , goprsc .HostOption (host ))
5072 options = append (options , goprsc .PortOption (port ))
5173 if useHTTPS {
5274 options = append (options , goprsc .HTTPSProtocolOption ())
5375 }
76+ if len (authToken ) > 0 {
77+ options = append (options , goprsc .AuthOption (login , authToken , refreshToken ))
78+ }
5479
5580 return goprsc .NewClientWithOptions (nil , options ... )
5681}
0 commit comments