-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package flag | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"time" | ||
|
||
"github.com/apex/log" | ||
"github.com/wesleimp/unleash-checkr/pkg/context" | ||
) | ||
|
||
var ( | ||
all = "all" | ||
active = "actives" | ||
inactive = "inactive" | ||
) | ||
|
||
// Get all flags | ||
func Get(ctx *context.Context) ([]Flag, error) { | ||
log.Info("Getting flags") | ||
|
||
url := fmt.Sprintf("%s/api/client/features", ctx.Config.URL) | ||
res, err := http.Get(url) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer res.Body.Close() | ||
|
||
var flags Flags | ||
err = json.NewDecoder(res.Body).Decode(&flags) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
ff := filter(ctx, flags.Features) | ||
|
||
return ff, nil | ||
} | ||
|
||
func filter(ctx *context.Context, flags []Flag) []Flag { | ||
const day = 24 * time.Hour | ||
dueDate := time.Now().Add(-time.Duration(ctx.Config.Expires) * day) | ||
dueDateUnix := dueDate.Unix() | ||
|
||
log.WithField("due-date", dueDate). | ||
Info("Filtering flags") | ||
|
||
var ff []Flag | ||
for _, f := range flags { | ||
if f.CreatedAt.Unix() < dueDateUnix { | ||
ff = append(ff, f) | ||
} | ||
} | ||
|
||
return ff | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package flag | ||
|
||
import "time" | ||
|
||
// Flags struct | ||
type Flags struct { | ||
Features []Flag `json:"features"` | ||
} | ||
|
||
// Flag struct | ||
type Flag struct { | ||
Name string `json:"name"` | ||
Description string `json:"description"` | ||
CreatedAt time.Time `json:"createdAt"` | ||
IsEnabled bool `json:"enabled"` | ||
} |