diff --git a/.gitignore b/.gitignore index e342370..3a54fc1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ # Created by https://www.toptal.com/developers/gitignore/api/windows,linux,goland+all,macos,go # Edit at https://www.toptal.com/developers/gitignore?templates=windows,linux,goland+all,macos,go +.env + ### Go ### # If you prefer the allow list template instead of the deny list, see community template: # https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore diff --git a/example/lowlevel/favorite.go b/example/lowlevel/favorite.go index 8be62c0..2be6701 100644 --- a/example/lowlevel/favorite.go +++ b/example/lowlevel/favorite.go @@ -3,17 +3,20 @@ package main import ( "git.dragse.it/anthrove/e621-to-graph/pkg/e621/endpoints" "git.dragse.it/anthrove/e621-to-graph/pkg/e621/model" + _ "github.com/joho/godotenv/autoload" "log" "net/http" + "os" ) func main() { // Define the request context with essential information. requestContext := model.RequestContext{ + Client: http.Client{}, Host: "https://e621.net", UserAgent: "Go-e621-SDK (@username)", - Username: "", // Replace with your username - APIKey: "", // Replace with your API key + Username: os.Getenv("API_USER"), // Replace with your username + APIKey: os.Getenv("API_KEY"), // Replace with your API key } // Log: Getting favorites from the API. diff --git a/example/lowlevel/note.go b/example/lowlevel/note.go index b4ea6c3..405dfce 100644 --- a/example/lowlevel/note.go +++ b/example/lowlevel/note.go @@ -3,17 +3,20 @@ package main import ( "git.dragse.it/anthrove/e621-to-graph/pkg/e621/endpoints" "git.dragse.it/anthrove/e621-to-graph/pkg/e621/model" + _ "github.com/joho/godotenv/autoload" "log" "net/http" + "os" ) func main() { // Define the request context with essential information. requestContext := model.RequestContext{ + Client: http.Client{}, Host: "https://e621.net", UserAgent: "Go-e621-SDK (@username)", - Username: "", // Replace with your username - APIKey: "", // Replace with your API key + Username: os.Getenv("API_USER"), // Replace with your username + APIKey: os.Getenv("API_KEY"), // Replace with your API key } // Log: Getting a single note. diff --git a/example/lowlevel/pool.go b/example/lowlevel/pool.go index d70b1f3..1f7aa70 100644 --- a/example/lowlevel/pool.go +++ b/example/lowlevel/pool.go @@ -3,17 +3,20 @@ package main import ( "git.dragse.it/anthrove/e621-to-graph/pkg/e621/endpoints" "git.dragse.it/anthrove/e621-to-graph/pkg/e621/model" + _ "github.com/joho/godotenv/autoload" "log" "net/http" + "os" ) func main() { // Define the request context with essential information. requestContext := model.RequestContext{ + Client: http.Client{}, Host: "https://e621.net", UserAgent: "Go-e621-SDK (@username)", - Username: "", // Replace with your username - APIKey: "", // Replace with your API key + Username: os.Getenv("API_USER"), // Replace with your username + APIKey: os.Getenv("API_KEY"), // Replace with your API key } // Log: Getting a single pool. diff --git a/example/lowlevel/post.go b/example/lowlevel/post.go index 1d59d23..e7e3fb0 100644 --- a/example/lowlevel/post.go +++ b/example/lowlevel/post.go @@ -3,17 +3,20 @@ package main import ( "git.dragse.it/anthrove/e621-to-graph/pkg/e621/endpoints" "git.dragse.it/anthrove/e621-to-graph/pkg/e621/model" + _ "github.com/joho/godotenv/autoload" "log" "net/http" + "os" ) func main() { // Define the request context with essential information. requestContext := model.RequestContext{ + Client: http.Client{}, Host: "https://e621.net", UserAgent: "Go-e621-SDK (@username)", - Username: "", // Replace with your username - APIKey: "", // Replace with your API key + Username: os.Getenv("API_USER"), // Replace with your username + APIKey: os.Getenv("API_KEY"), // Replace with your API key } // Log: Getting a single post. diff --git a/example/lowlevel/tag.go b/example/lowlevel/tag.go index 318efd2..36110de 100644 --- a/example/lowlevel/tag.go +++ b/example/lowlevel/tag.go @@ -3,30 +3,30 @@ package main import ( "git.dragse.it/anthrove/e621-to-graph/pkg/e621/endpoints" "git.dragse.it/anthrove/e621-to-graph/pkg/e621/model" + _ "github.com/joho/godotenv/autoload" "log" "net/http" + "os" ) func main() { // Define the request context with essential information. requestContext := model.RequestContext{ + Client: http.Client{}, Host: "https://e621.net", UserAgent: "Go-e621-SDK (@username)", - Username: "", // Replace with your username - APIKey: "", // Replace with your API key + Username: os.Getenv("API_USER"), // Replace with your username + APIKey: os.Getenv("API_KEY"), // Replace with your API key } // Log: Getting a single tag. log.Println("Getting a single tag: ") - // Initialize an http.Client. - client := http.Client{} - // Specify the tag ID for retrieval. tagID := "1530" // Replace with the desired tag's ID. // Call the GetTag function to retrieve the specified tag. - tag, err := endpoints.GetTag(client, requestContext, tagID) + tag, err := endpoints.GetTag(requestContext, tagID) if err != nil { log.Println(err) @@ -45,7 +45,7 @@ func main() { } // Call the GetTags function to retrieve a list of tags based on the query parameters. - tagList, err := endpoints.GetTags(client, requestContext, query) + tagList, err := endpoints.GetTags(requestContext, query) if err != nil { log.Println(err) @@ -65,7 +65,7 @@ func main() { } // Call the GetTags function with the search query to retrieve matching tags. - tagList, err = endpoints.GetTags(client, requestContext, query) + tagList, err = endpoints.GetTags(requestContext, query) if err != nil { log.Println(err) @@ -85,7 +85,7 @@ func main() { } // Call the GetTags function with the category filter to retrieve artist tags. - tagList, err = endpoints.GetTags(client, requestContext, query) + tagList, err = endpoints.GetTags(requestContext, query) if err != nil { log.Println(err) diff --git a/example/lowlevel/user.go b/example/lowlevel/user.go index 2d22582..a7491b4 100644 --- a/example/lowlevel/user.go +++ b/example/lowlevel/user.go @@ -3,8 +3,10 @@ package main import ( "git.dragse.it/anthrove/e621-to-graph/pkg/e621/endpoints" "git.dragse.it/anthrove/e621-to-graph/pkg/e621/model" + _ "github.com/joho/godotenv/autoload" "log" "net/http" + "os" ) func main() { @@ -13,8 +15,8 @@ func main() { Client: http.Client{}, Host: "https://e621.net", UserAgent: "Go-e621-SDK (@username)", - Username: "", // Replace with your username - APIKey: "", // Replace with your API key + Username: os.Getenv("API_USER"), // Replace with your username + APIKey: os.Getenv("API_KEY"), // Replace with your API key } // Log: Getting a single user. diff --git a/example/midlevel/tag.go b/example/midlevel/tag.go index 0784022..cdfee84 100644 --- a/example/midlevel/tag.go +++ b/example/midlevel/tag.go @@ -3,8 +3,10 @@ package main import ( "git.dragse.it/anthrove/e621-to-graph/pkg/e621/builder" "git.dragse.it/anthrove/e621-to-graph/pkg/e621/model" + _ "github.com/joho/godotenv/autoload" "log" "net/http" + "os" ) func main() { @@ -13,8 +15,8 @@ func main() { Client: http.Client{}, Host: "https://e621.net", UserAgent: "Go-e621-SDK (@username)", - Username: "", // Replace with your username - APIKey: "", // Replace with your API key + Username: os.Getenv("API_USER"), // Replace with your username + APIKey: os.Getenv("API_KEY"), // Replace with your API key } // Log: Getting a single tag. diff --git a/example/midlevel/user.go b/example/midlevel/user.go index 0cbde8a..a492006 100644 --- a/example/midlevel/user.go +++ b/example/midlevel/user.go @@ -3,8 +3,10 @@ package main import ( "git.dragse.it/anthrove/e621-to-graph/pkg/e621/builder" "git.dragse.it/anthrove/e621-to-graph/pkg/e621/model" + _ "github.com/joho/godotenv/autoload" "log" "net/http" + "os" ) func main() { @@ -13,8 +15,8 @@ func main() { Client: http.Client{}, Host: "https://e621.net", UserAgent: "Go-e621-SDK (@username)", - Username: "", // Replace with your username - APIKey: "", // Replace with your API key + Username: os.Getenv("API_USER"), // Replace with your username + APIKey: os.Getenv("API_KEY"), // Replace with your API key } // Log: Getting a single user. diff --git a/go.mod b/go.mod index 34f5bda..9f3b86f 100644 --- a/go.mod +++ b/go.mod @@ -5,4 +5,5 @@ go 1.21.3 require ( github.com/google/go-cmp v0.6.0 // indirect github.com/jarcoal/httpmock v1.3.1 // indirect + github.com/joho/godotenv v1.5.1 // indirect ) diff --git a/go.sum b/go.sum index eb26d26..d98f698 100644 --- a/go.sum +++ b/go.sum @@ -2,3 +2,5 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/jarcoal/httpmock v1.3.1 h1:iUx3whfZWVf3jT01hQTO/Eo5sAYtB2/rqaUuOtpInww= github.com/jarcoal/httpmock v1.3.1/go.mod h1:3yb8rc4BI7TCBhFY8ng0gjuLKJNquuDNiPaZjnENuYg= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=