Skip to content

Commit

Permalink
get rid of archived hierr-go package
Browse files Browse the repository at this point in the history
  • Loading branch information
kovetskiy committed Feb 7, 2019
1 parent aad375f commit 4abc40e
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 38 deletions.
6 changes: 3 additions & 3 deletions handle_latest_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"
"text/tabwriter"

"github.com/zazab/hierr"
"github.com/reconquest/karma-go"
)

func handleLatestData(
Expand Down Expand Up @@ -50,7 +50,7 @@ func handleLatestData(
)

if err != nil {
return hierr.Errorf(
return karma.Format(
err,
"can't obtain zabbix hosts",
)
Expand Down Expand Up @@ -112,7 +112,7 @@ func handleLatestData(
)

if err != nil {
return hierr.Errorf(
return karma.Format(
err,
"can't obtain zabbix items",
)
Expand Down
14 changes: 7 additions & 7 deletions handle_triggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"strings"
"text/tabwriter"

"github.com/reconquest/karma-go"
"github.com/simplereach/timeutils"
"github.com/zazab/hierr"
)

type ExtendedOutput int
Expand Down Expand Up @@ -56,7 +56,7 @@ func handleTriggers(
},
)
if err != nil {
return hierr.Errorf(
return karma.Format(
err,
"can't obtain zabbix triggers",
)
Expand All @@ -67,7 +67,7 @@ func handleTriggers(
if extended != ExtendedOutputNone {
history, err = getTriggerItemsHistory(zabbix, triggers)
if err != nil {
return hierr.Errorf(
return karma.Format(
err,
`can't obtain history for items of triggers`,
)
Expand Down Expand Up @@ -140,7 +140,7 @@ func handleTriggers(
)

if err != nil {
return hierr.Errorf(
return karma.Format(
err,
"can't acknowledge triggers %s",
identifiers,
Expand Down Expand Up @@ -169,7 +169,7 @@ func getTriggerItemsHistory(
"itemids": itemIDs,
})
if err != nil {
return nil, hierr.Errorf(
return nil, karma.Format(
err,
`can't obtain items of triggers`,
)
Expand All @@ -185,7 +185,7 @@ func getTriggerItemsHistory(
"limit": 1,
})
if err != nil {
return hierr.Errorf(
return karma.Format(
err,
`can't obtain history (type '%s') for item '%s'`,
item.ValueType,
Expand Down Expand Up @@ -260,7 +260,7 @@ func parseParams(args map[string]interface{}) (Params, error) {
func parseDateTime(value string) (int64, error) {
date, err := timeutils.ParseDateString(value)
if err != nil {
return 0, hierr.Errorf(err, "can't parse datetime '%s'", value)
return 0, karma.Format(err, "can't parse datetime '%s'", value)
}

return date.Unix(), nil
Expand Down
18 changes: 9 additions & 9 deletions handle_users_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
"text/tabwriter"

"github.com/zazab/hierr"
"github.com/reconquest/karma-go"
)

func handleUsersGroups(
Expand Down Expand Up @@ -37,7 +37,7 @@ func handleUsersGroups(
)

if err != nil {
return hierr.Errorf(
return karma.Format(
err,
"can't obtain users groups %s", groups,
)
Expand Down Expand Up @@ -80,7 +80,7 @@ func handleUsersGroups(

user, err := getUser(zabbix, addUser)
if err != nil {
return hierr.Errorf(
return karma.Format(
err,
"can't obtain user '%s'", addUser,
)
Expand All @@ -94,7 +94,7 @@ func handleUsersGroups(
)

if err != nil {
return hierr.Errorf(
return karma.Format(
err,
"can't add user '%s' to specified users groups",
user.Alias,
Expand All @@ -110,7 +110,7 @@ func handleUsersGroups(

user, err := getUser(zabbix, removeUser)
if err != nil {
return hierr.Errorf(
return karma.Format(
err,
"can't obtain user '%s'", removeUser,
)
Expand All @@ -124,7 +124,7 @@ func handleUsersGroups(
)

if err != nil {
return hierr.Errorf(
return karma.Format(
err,
"can't remove user '%s' from specified users groups",
removeUser,
Expand All @@ -142,7 +142,7 @@ func getUser(zabbix *Zabbix, username string) (User, error) {
},
})
if err != nil {
return User{}, hierr.Errorf(
return User{}, karma.Format(
err, "can't obtain user with specified name",
)
}
Expand Down Expand Up @@ -172,7 +172,7 @@ func getUsersGroups(zabbix *Zabbix, groups []string) ([]UserGroup, error) {

usersgroups, err := zabbix.GetUsersGroups(params)
if err != nil {
return nil, hierr.Errorf(
return nil, karma.Format(
err,
"can't obtain zabbix users groups",
)
Expand All @@ -195,7 +195,7 @@ func getUsersGroups(zabbix *Zabbix, groups []string) ([]UserGroup, error) {
},
)
if err != nil {
return nil, hierr.Errorf(
return nil, karma.Format(
err,
"can't obtain users from specified groups %q",
usersIdentifiers,
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/kovetskiy/godocs"
"github.com/kovetskiy/lorg"
"github.com/kovetskiy/spinner-go"
"github.com/zazab/hierr"
"github.com/reconquest/karma-go"
)

var (
Expand Down Expand Up @@ -42,7 +42,7 @@ func main() {
config, err := NewConfig(args["--config"].(string))
if err != nil {
fatalln(
hierr.Errorf(
karma.Format(
err,
"problem with configuration",
),
Expand Down
4 changes: 2 additions & 2 deletions responses.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package main

import "github.com/reconquest/hierr-go"
import "github.com/reconquest/karma-go"

type Response interface {
Error() error
Expand All @@ -17,7 +17,7 @@ type ResponseRaw struct {

func (response *ResponseRaw) Error() error {
if response.Err.Data != "" && response.Err.Message != "" {
return hierr.Push(
return karma.Push(
response.Err.Message,
response.Err.Data,
)
Expand Down
30 changes: 15 additions & 15 deletions zabbix.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"sync/atomic"
"time"

"github.com/zazab/hierr"
"github.com/reconquest/karma-go"
)

const (
Expand Down Expand Up @@ -59,7 +59,7 @@ func NewZabbix(

err = zabbix.restoreSession(sessionFile)
if err != nil {
return nil, hierr.Errorf(
return nil, karma.Format(
err,
"can't restore zabbix session using file '%s'",
sessionFile,
Expand All @@ -72,7 +72,7 @@ func NewZabbix(
if zabbix.session == "" {
err = zabbix.Login(username, password)
if err != nil {
return nil, hierr.Errorf(
return nil, karma.Format(
err,
"can't authorize user '%s' in zabbix server",
username,
Expand All @@ -88,7 +88,7 @@ func NewZabbix(
// always rewrite session file, it will change modify date
err = zabbix.saveSession(sessionFile)
if err != nil {
return nil, hierr.Errorf(
return nil, karma.Format(
err,
"can't save zabbix session to file '%s'",
)
Expand All @@ -103,22 +103,22 @@ func (zabbix *Zabbix) restoreSession(path string) error {
path, os.O_CREATE|os.O_RDWR, 0600,
)
if err != nil {
return hierr.Errorf(
return karma.Format(
err, "can't open session file",
)
}

stat, err := file.Stat()
if err != nil {
return hierr.Errorf(
return karma.Format(
err, "can't stat session file",
)
}

if time.Now().Sub(stat.ModTime()).Seconds() < ZabbixSessionTTL {
session, err := ioutil.ReadAll(file)
if err != nil {
return hierr.Errorf(
return karma.Format(
err, "can't read session file",
)
}
Expand All @@ -134,7 +134,7 @@ func (zabbix *Zabbix) restoreSession(path string) error {
func (zabbix *Zabbix) saveSession(path string) error {
err := ioutil.WriteFile(path, []byte(zabbix.session), 0600)
if err != nil {
return hierr.Errorf(
return karma.Format(
err,
"can't write session file",
)
Expand Down Expand Up @@ -271,7 +271,7 @@ func (zabbix *Zabbix) AddUserToGroups(
&ResponseRaw{},
)
if err != nil {
return hierr.Errorf(
return karma.Format(
err,
"can't update usergroup %s", group.Name,
)
Expand Down Expand Up @@ -304,7 +304,7 @@ func (zabbix *Zabbix) RemoveUserFromGroups(
&ResponseRaw{},
)
if err != nil {
return hierr.Errorf(
return karma.Format(
err,
"can't update usergroup %s", group.Name,
)
Expand Down Expand Up @@ -410,7 +410,7 @@ func (zabbix *Zabbix) call(

buffer, err := json.Marshal(request)
if err != nil {
return hierr.Errorf(
return karma.Format(
err,
"can't encode request to JSON",
)
Expand All @@ -422,7 +422,7 @@ func (zabbix *Zabbix) call(
bytes.NewReader(buffer),
)
if err != nil {
return hierr.Errorf(
return karma.Format(
err,
"can't create http request",
)
Expand All @@ -434,15 +434,15 @@ func (zabbix *Zabbix) call(

resource, err := zabbix.client.Do(payload)
if err != nil {
return hierr.Errorf(
return karma.Format(
err,
"http request to zabbix api failed",
)
}

body, err := ioutil.ReadAll(resource.Body)
if err != nil {
return hierr.Errorf(
return karma.Format(
err,
"can't read zabbix api response body",
)
Expand Down Expand Up @@ -479,7 +479,7 @@ func (zabbix *Zabbix) call(

err = response.Error()
if err != nil {
return hierr.Errorf(
return karma.Format(
err,
"zabbix returned error while working with api method %s",
method,
Expand Down

0 comments on commit 4abc40e

Please sign in to comment.