https://github.com/lyubenblagoev/goprsc
Goprsc is a GO client library for the Postfix Rest Server
https://github.com/lyubenblagoev/goprsc
golang library postfix-rest-server
Last synced: 6 months ago
JSON representation
Goprsc is a GO client library for the Postfix Rest Server
- Host: GitHub
- URL: https://github.com/lyubenblagoev/goprsc
- Owner: lyubenblagoev
- License: mit
- Created: 2017-06-21T18:09:58.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2021-03-16T15:50:15.000Z (over 5 years ago)
- Last Synced: 2023-07-27T22:19:59.787Z (almost 3 years ago)
- Topics: golang, library, postfix-rest-server
- Language: Go
- Homepage:
- Size: 24.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Goprsc
Goprsc is a GO client library for accessing the [Postfix Rest Server][1] V1 API.
Goprsc currently implements all [Postfix Rest Server][1] APIs (domains, accounts, aliases, automatic sender and recipient BCC).
## Usage
```go
import "github.com/lyubenblagoev/goprsc"
```
Create a new client and use the exposed services to access different parts of the [Postfix Rest Server][1] API.
Use the DefaultClient:
```go
client := goprsc.DefaultClient
```
Create a new Client using NewClient(*http.Client):
```go
var httpClient *http.Client
...
client := goprsc.NewClient(httpClient)
```
Create a new client using NewClientWithOptions(*http.Client, ...ClientOption):
```go
client := goprsc.NewClientWithOptions(nil, HTTPSProtocolOption())
```
Client options allow changing the default protocol, host, port and user agent string using HTTPSProtocolOption(), HostOption(), PortOption() and UserAgentOption() functions. These functions return a ClientOption which changes the corresponding option in the client.
## Examples
To create a new domain:
```go
client := goprsc.DefaultClient
domainName := "example.com"
if err := client.Domains.Create(domainName); err != nil {
fmt.Printf("Unable to create domain %s\n\n", domainName)
return err
}
```
To get a list of all accounts in a domain:
```go
client := goprsc.DefaultClient
domainName := "example.com"
accounts, err := client.Accounts.List(domainName)
if err != nil {
fmt.Printf("Unable to list accounts for domain %s\n\n", domainName)
return err
}
```
Similarly you can manage other entities.
For more usage examples, you may wish to take a look at [emailctl][2] (a CLI for the [Postfix Rest Server][1]).
[1]: https://github.com/lyubenblagoev/postfix-rest-server "Postfix Rest Server"
[2]: https://github.com/lyubenblagoev/emailctl "emailctl"