Skip to content

Commit

Permalink
log start and end
Browse files Browse the repository at this point in the history
  • Loading branch information
bakito committed Mar 28, 2021
1 parent 4bcfadc commit 785c23a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
11 changes: 11 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package main
import (
"os"

"github.com/bakito/adguardhome-sync/pkg/log"

"github.com/bakito/adguardhome-sync/pkg/client"
)

Expand All @@ -15,6 +17,10 @@ const (
envOReplicaPassword = "REPLICA_PASSWORD"
)

var (
l = log.GetLogger("main")
)

func main() {

origin, err := client.New(os.Getenv(envOriginApiURL), os.Getenv(envOriginUsername), os.Getenv(envOriginPassword))
Expand All @@ -26,6 +32,11 @@ func main() {
panic(err)
}

logger := l.With("from", origin.Host(), "to", replica.Host())

logger.Info("Start sync")
defer func() { logger.Info("Sync done") }()

os, err := origin.Status()
if err != nil {
panic(err)
Expand Down
7 changes: 7 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ func New(apiURL string, username string, password string) (Client, error) {
}

return &client{
host: u.Host,
client: cl,
log: l.With("host", u.Host),
}, nil
}

type Client interface {
Host() string

Status() (*types.Status, error)
RewriteList() (*types.RewriteEntries, error)
AddRewriteEntries(e ...types.RewriteEntry) error
Expand Down Expand Up @@ -61,8 +64,12 @@ type Client interface {
type client struct {
client *resty.Client
log *zap.SugaredLogger
host string
}

func (cl *client) Host() string {
return cl.host
}
func (cl *client) Status() (*types.Status, error) {
status := &types.Status{}
_, err := cl.client.R().EnableTrace().SetResult(status).Get("status")
Expand Down

0 comments on commit 785c23a

Please sign in to comment.