Skip to content

Commit

Permalink
Adding examples, fixing the go.mod file and some general improvements (
Browse files Browse the repository at this point in the history
  • Loading branch information
fear-the-reaper authored Aug 28, 2022
1 parent d6da4b7 commit 6844dbe
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 18 deletions.
1 change: 1 addition & 0 deletions examples/basicExample/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func main() {
Url: "PUT-YOUR-INTELOWL-INSTANCE-URL-HERE",
Token: "PUT-YOUR-TOKEN-HERE",
Certificate: "",
Timeout: 0,
}

loggerParams := &gointelowl.LoggerParams{
Expand Down
57 changes: 57 additions & 0 deletions examples/client/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package main

import (
"context"

"github.com/intelowlproject/go-intelowl/gointelowl"
"github.com/sirupsen/logrus"
)

func main() {
/*
Making a new client through NewIntelOwlClient:
This takes the following parameters:
1. IntelOwlClientOptions
2. A *http.Client (if you do not provide one. One will be made by default)
3. LoggerParams
These are parameters that allow you to easily configure your IntelOwlClient to your liking.
For a better understanding you can read it in the documentation: https://github.com/intelowlproject/go-intelowl/tree/main/examples/optionalParams
*/

// Configuring the IntelOwlClient!
clientOptions := gointelowl.IntelOwlClientOptions{
Url: "PUT-YOUR-INTELOWL-INSTANCE-URL-HERE",
Token: "PUT-YOUR-TOKEN-HERE",
Certificate: "",
Timeout: 0,
}

// Configuring the logger
loggerParams := &gointelowl.LoggerParams{
File: nil,
Formatter: &logrus.JSONFormatter{},
Level: logrus.DebugLevel,
}

// Making the client!
client := gointelowl.NewIntelOwlClient(
&clientOptions,
nil,
loggerParams,
)

ctx := context.Background()

tags, err := client.TagService.List(ctx)

if err != nil {
client.Logger.Logger.WithFields(logrus.Fields{
"error": err.Error(),
}).Error("An error occurred")
} else {
client.Logger.Logger.WithFields(logrus.Fields{
"tags": *tags,
}).Info("These are your tags")
}

}
15 changes: 13 additions & 2 deletions examples/client/client.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
<!-- Will be revised when I'll add the custom logger and easy ways of setting the client up! -->
# Client
A good client is a client that is easy to use, configurable and customizable to a user’s liking. Hence, the client has 2 great features:
A good client is a client that is easy to use, configurable and customizable to a user’s liking. Hence, the client has 4 great features:
1. Configurable HTTP client
2. Customizable timeouts
3. Logger
4. Easy ways to create the `IntelOwlClient`

## Configurable HTTP client
Now from the documentation, you can see you can pass your `http.Client`. This is to facilitate each user’s requirement and taste! If you don’t pass one (`nil`) a default `http.Client` will be made for you!

## Customizable timeouts
From `IntelOwlClientOptions` you can add your own timeout to your requests as well.
From `IntelOwlClientOptions` you can add your own timeout to your requests as well.

## Logger
To ease developers' work go-intelowl provides a logger for easy debugging and tracking! For the logger we used [logrus](https://github.com/sirupsen/logrus) because of 2 reasons:
1. Easy to use
2. Extensible to your liking

## Easy ways to create the `IntelOwlClient`
As you know working with Golang structs is sometimes cumbersome we thought we could provide a simple way to create the client in a way that helps speed up development. This gave birth to the idea of using a `JSON` file to create the IntelOwlClient. The method `NewIntelOwlClientThroughJsonFile` does exactly that. Send the `IntelOwlClientOptions` JSON file path with your http.Client and LoggerParams in this method and you'll get the IntelOwlClient!

11 changes: 4 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ module github.com/intelowlproject/go-intelowl
go 1.17

require (
github.com/google/go-cmp v0.5.8 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/yuin/goldmark v1.4.13 // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
golang.org/x/tools v0.1.12 // indirect
github.com/google/go-cmp v0.5.8
github.com/sirupsen/logrus v1.9.0
)

require golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
13 changes: 4 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 comments on commit 6844dbe

Please sign in to comment.