feat: using env variables to stop leaking my key...

Signed-off-by: SoXX <soxx@fenpa.ws>
This commit is contained in:
SoXX 2023-10-23 11:24:48 +02:00
parent f69c1b14a3
commit 64a9623b3c
11 changed files with 46 additions and 23 deletions

2
.gitignore vendored
View File

@ -1,6 +1,8 @@
# Created by https://www.toptal.com/developers/gitignore/api/windows,linux,goland+all,macos,go # 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 # Edit at https://www.toptal.com/developers/gitignore?templates=windows,linux,goland+all,macos,go
.env
### Go ### ### Go ###
# If you prefer the allow list template instead of the deny list, see community template: # 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 # https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore

View File

@ -3,17 +3,20 @@ package main
import ( import (
"git.dragse.it/anthrove/e621-to-graph/pkg/e621/endpoints" "git.dragse.it/anthrove/e621-to-graph/pkg/e621/endpoints"
"git.dragse.it/anthrove/e621-to-graph/pkg/e621/model" "git.dragse.it/anthrove/e621-to-graph/pkg/e621/model"
_ "github.com/joho/godotenv/autoload"
"log" "log"
"net/http" "net/http"
"os"
) )
func main() { func main() {
// Define the request context with essential information. // Define the request context with essential information.
requestContext := model.RequestContext{ requestContext := model.RequestContext{
Client: http.Client{},
Host: "https://e621.net", Host: "https://e621.net",
UserAgent: "Go-e621-SDK (@username)", UserAgent: "Go-e621-SDK (@username)",
Username: "", // Replace with your username Username: os.Getenv("API_USER"), // Replace with your username
APIKey: "", // Replace with your API key APIKey: os.Getenv("API_KEY"), // Replace with your API key
} }
// Log: Getting favorites from the API. // Log: Getting favorites from the API.

View File

@ -3,17 +3,20 @@ package main
import ( import (
"git.dragse.it/anthrove/e621-to-graph/pkg/e621/endpoints" "git.dragse.it/anthrove/e621-to-graph/pkg/e621/endpoints"
"git.dragse.it/anthrove/e621-to-graph/pkg/e621/model" "git.dragse.it/anthrove/e621-to-graph/pkg/e621/model"
_ "github.com/joho/godotenv/autoload"
"log" "log"
"net/http" "net/http"
"os"
) )
func main() { func main() {
// Define the request context with essential information. // Define the request context with essential information.
requestContext := model.RequestContext{ requestContext := model.RequestContext{
Client: http.Client{},
Host: "https://e621.net", Host: "https://e621.net",
UserAgent: "Go-e621-SDK (@username)", UserAgent: "Go-e621-SDK (@username)",
Username: "", // Replace with your username Username: os.Getenv("API_USER"), // Replace with your username
APIKey: "", // Replace with your API key APIKey: os.Getenv("API_KEY"), // Replace with your API key
} }
// Log: Getting a single note. // Log: Getting a single note.

View File

@ -3,17 +3,20 @@ package main
import ( import (
"git.dragse.it/anthrove/e621-to-graph/pkg/e621/endpoints" "git.dragse.it/anthrove/e621-to-graph/pkg/e621/endpoints"
"git.dragse.it/anthrove/e621-to-graph/pkg/e621/model" "git.dragse.it/anthrove/e621-to-graph/pkg/e621/model"
_ "github.com/joho/godotenv/autoload"
"log" "log"
"net/http" "net/http"
"os"
) )
func main() { func main() {
// Define the request context with essential information. // Define the request context with essential information.
requestContext := model.RequestContext{ requestContext := model.RequestContext{
Client: http.Client{},
Host: "https://e621.net", Host: "https://e621.net",
UserAgent: "Go-e621-SDK (@username)", UserAgent: "Go-e621-SDK (@username)",
Username: "", // Replace with your username Username: os.Getenv("API_USER"), // Replace with your username
APIKey: "", // Replace with your API key APIKey: os.Getenv("API_KEY"), // Replace with your API key
} }
// Log: Getting a single pool. // Log: Getting a single pool.

View File

@ -3,17 +3,20 @@ package main
import ( import (
"git.dragse.it/anthrove/e621-to-graph/pkg/e621/endpoints" "git.dragse.it/anthrove/e621-to-graph/pkg/e621/endpoints"
"git.dragse.it/anthrove/e621-to-graph/pkg/e621/model" "git.dragse.it/anthrove/e621-to-graph/pkg/e621/model"
_ "github.com/joho/godotenv/autoload"
"log" "log"
"net/http" "net/http"
"os"
) )
func main() { func main() {
// Define the request context with essential information. // Define the request context with essential information.
requestContext := model.RequestContext{ requestContext := model.RequestContext{
Client: http.Client{},
Host: "https://e621.net", Host: "https://e621.net",
UserAgent: "Go-e621-SDK (@username)", UserAgent: "Go-e621-SDK (@username)",
Username: "", // Replace with your username Username: os.Getenv("API_USER"), // Replace with your username
APIKey: "", // Replace with your API key APIKey: os.Getenv("API_KEY"), // Replace with your API key
} }
// Log: Getting a single post. // Log: Getting a single post.

View File

@ -3,30 +3,30 @@ package main
import ( import (
"git.dragse.it/anthrove/e621-to-graph/pkg/e621/endpoints" "git.dragse.it/anthrove/e621-to-graph/pkg/e621/endpoints"
"git.dragse.it/anthrove/e621-to-graph/pkg/e621/model" "git.dragse.it/anthrove/e621-to-graph/pkg/e621/model"
_ "github.com/joho/godotenv/autoload"
"log" "log"
"net/http" "net/http"
"os"
) )
func main() { func main() {
// Define the request context with essential information. // Define the request context with essential information.
requestContext := model.RequestContext{ requestContext := model.RequestContext{
Client: http.Client{},
Host: "https://e621.net", Host: "https://e621.net",
UserAgent: "Go-e621-SDK (@username)", UserAgent: "Go-e621-SDK (@username)",
Username: "", // Replace with your username Username: os.Getenv("API_USER"), // Replace with your username
APIKey: "", // Replace with your API key APIKey: os.Getenv("API_KEY"), // Replace with your API key
} }
// Log: Getting a single tag. // Log: Getting a single tag.
log.Println("Getting a single tag: ") log.Println("Getting a single tag: ")
// Initialize an http.Client.
client := http.Client{}
// Specify the tag ID for retrieval. // Specify the tag ID for retrieval.
tagID := "1530" // Replace with the desired tag's ID. tagID := "1530" // Replace with the desired tag's ID.
// Call the GetTag function to retrieve the specified tag. // 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 { if err != nil {
log.Println(err) log.Println(err)
@ -45,7 +45,7 @@ func main() {
} }
// Call the GetTags function to retrieve a list of tags based on the query parameters. // 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 { if err != nil {
log.Println(err) log.Println(err)
@ -65,7 +65,7 @@ func main() {
} }
// Call the GetTags function with the search query to retrieve matching tags. // 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 { if err != nil {
log.Println(err) log.Println(err)
@ -85,7 +85,7 @@ func main() {
} }
// Call the GetTags function with the category filter to retrieve artist tags. // 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 { if err != nil {
log.Println(err) log.Println(err)

View File

@ -3,8 +3,10 @@ package main
import ( import (
"git.dragse.it/anthrove/e621-to-graph/pkg/e621/endpoints" "git.dragse.it/anthrove/e621-to-graph/pkg/e621/endpoints"
"git.dragse.it/anthrove/e621-to-graph/pkg/e621/model" "git.dragse.it/anthrove/e621-to-graph/pkg/e621/model"
_ "github.com/joho/godotenv/autoload"
"log" "log"
"net/http" "net/http"
"os"
) )
func main() { func main() {
@ -13,8 +15,8 @@ func main() {
Client: http.Client{}, Client: http.Client{},
Host: "https://e621.net", Host: "https://e621.net",
UserAgent: "Go-e621-SDK (@username)", UserAgent: "Go-e621-SDK (@username)",
Username: "", // Replace with your username Username: os.Getenv("API_USER"), // Replace with your username
APIKey: "", // Replace with your API key APIKey: os.Getenv("API_KEY"), // Replace with your API key
} }
// Log: Getting a single user. // Log: Getting a single user.

View File

@ -3,8 +3,10 @@ package main
import ( import (
"git.dragse.it/anthrove/e621-to-graph/pkg/e621/builder" "git.dragse.it/anthrove/e621-to-graph/pkg/e621/builder"
"git.dragse.it/anthrove/e621-to-graph/pkg/e621/model" "git.dragse.it/anthrove/e621-to-graph/pkg/e621/model"
_ "github.com/joho/godotenv/autoload"
"log" "log"
"net/http" "net/http"
"os"
) )
func main() { func main() {
@ -13,8 +15,8 @@ func main() {
Client: http.Client{}, Client: http.Client{},
Host: "https://e621.net", Host: "https://e621.net",
UserAgent: "Go-e621-SDK (@username)", UserAgent: "Go-e621-SDK (@username)",
Username: "", // Replace with your username Username: os.Getenv("API_USER"), // Replace with your username
APIKey: "", // Replace with your API key APIKey: os.Getenv("API_KEY"), // Replace with your API key
} }
// Log: Getting a single tag. // Log: Getting a single tag.

View File

@ -3,8 +3,10 @@ package main
import ( import (
"git.dragse.it/anthrove/e621-to-graph/pkg/e621/builder" "git.dragse.it/anthrove/e621-to-graph/pkg/e621/builder"
"git.dragse.it/anthrove/e621-to-graph/pkg/e621/model" "git.dragse.it/anthrove/e621-to-graph/pkg/e621/model"
_ "github.com/joho/godotenv/autoload"
"log" "log"
"net/http" "net/http"
"os"
) )
func main() { func main() {
@ -13,8 +15,8 @@ func main() {
Client: http.Client{}, Client: http.Client{},
Host: "https://e621.net", Host: "https://e621.net",
UserAgent: "Go-e621-SDK (@username)", UserAgent: "Go-e621-SDK (@username)",
Username: "", // Replace with your username Username: os.Getenv("API_USER"), // Replace with your username
APIKey: "", // Replace with your API key APIKey: os.Getenv("API_KEY"), // Replace with your API key
} }
// Log: Getting a single user. // Log: Getting a single user.

1
go.mod
View File

@ -5,4 +5,5 @@ go 1.21.3
require ( require (
github.com/google/go-cmp v0.6.0 // indirect github.com/google/go-cmp v0.6.0 // indirect
github.com/jarcoal/httpmock v1.3.1 // indirect github.com/jarcoal/httpmock v1.3.1 // indirect
github.com/joho/godotenv v1.5.1 // indirect
) )

2
go.sum
View File

@ -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/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 h1:iUx3whfZWVf3jT01hQTO/Eo5sAYtB2/rqaUuOtpInww=
github.com/jarcoal/httpmock v1.3.1/go.mod h1:3yb8rc4BI7TCBhFY8ng0gjuLKJNquuDNiPaZjnENuYg= 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=