mirror of
https://codeberg.org/ultimateplayer1999/go-api-usage.git
synced 2024-11-22 05:48:22 -05:00
Added source and prebuilds
This commit is contained in:
parent
192cf8bd75
commit
84c7831e7c
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
.env
|
||||
go.sum
|
||||
go.mod
|
||||
stats.go
|
||||
stats
|
@ -1 +1,3 @@
|
||||
Some examples for API usage in Go for the ssh.surf API
|
||||
|
||||
All of them based on .env files
|
||||
|
BIN
containerinfo
Executable file
BIN
containerinfo
Executable file
Binary file not shown.
47
containerinfo.go
Normal file
47
containerinfo.go
Normal file
@ -0,0 +1,47 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"log"
|
||||
"fmt"
|
||||
"os"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Load environment variables from .env file
|
||||
err := godotenv.Load()
|
||||
if err != nil {
|
||||
log.Fatal("Error loading .env file")
|
||||
}
|
||||
|
||||
token := os.Getenv("TOKEN")
|
||||
|
||||
// Make an HTTP request to api.discord-linux.com
|
||||
req, err := http.NewRequest("GET", "https://api.discord-linux.com/info", nil)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
req.Header.Set("Accept", "application/json")
|
||||
req.Header.Add("Content-Type", "Application/json")
|
||||
req.Header.Add("x-discord-linux-auth", token)
|
||||
|
||||
client := http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
fmt.Println("Status code: ", resp.StatusCode)
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Println(string(body))
|
||||
|
||||
}
|
BIN
containertime
Executable file
BIN
containertime
Executable file
Binary file not shown.
47
containertime.go
Normal file
47
containertime.go
Normal file
@ -0,0 +1,47 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"log"
|
||||
"fmt"
|
||||
"os"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Load environment variables from .env file
|
||||
err := godotenv.Load()
|
||||
if err != nil {
|
||||
log.Fatal("Error loading .env file")
|
||||
}
|
||||
|
||||
token := os.Getenv("TOKEN")
|
||||
|
||||
// Make an HTTP request to api.discord-linux.com
|
||||
req, err := http.NewRequest("GET", "https://api.discord-linux.com/time", nil)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
req.Header.Set("Accept", "application/json")
|
||||
req.Header.Add("Content-Type", "Application/json")
|
||||
req.Header.Add("x-discord-linux-auth", token)
|
||||
|
||||
client := http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
fmt.Println("Status code: ", resp.StatusCode)
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Println(string(body))
|
||||
|
||||
}
|
47
hello.go
Normal file
47
hello.go
Normal file
@ -0,0 +1,47 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"log"
|
||||
"fmt"
|
||||
"os"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Load environment variables from .env file
|
||||
err := godotenv.Load()
|
||||
if err != nil {
|
||||
log.Fatal("Error loading .env file")
|
||||
}
|
||||
|
||||
token := os.Getenv("TOKEN")
|
||||
|
||||
// Make an HTTP request to api.discord-linux.com
|
||||
req, err := http.NewRequest("GET", "https://api.discord-linux.com/hello", nil)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
req.Header.Set("Accept", "application/json")
|
||||
req.Header.Add("Content-Type", "Application/json")
|
||||
req.Header.Add("x-discord-linux-auth", token)
|
||||
|
||||
client := http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
fmt.Println("Status code: ", resp.StatusCode)
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Println(string(body))
|
||||
|
||||
}
|
47
keystatus.go
Normal file
47
keystatus.go
Normal file
@ -0,0 +1,47 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"log"
|
||||
"fmt"
|
||||
"os"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Load environment variables from .env file
|
||||
err := godotenv.Load()
|
||||
if err != nil {
|
||||
log.Fatal("Error loading .env file")
|
||||
}
|
||||
|
||||
token := os.Getenv("TOKEN")
|
||||
|
||||
// Make an HTTP request to api.discord-linux.com
|
||||
req, err := http.NewRequest("GET", "https://api.discord-linux.com/key-time", nil)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
req.Header.Set("Accept", "application/json")
|
||||
req.Header.Add("Content-Type", "Application/json")
|
||||
req.Header.Add("x-discord-linux-auth", token)
|
||||
|
||||
client := http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
fmt.Println("Status code: ", resp.StatusCode)
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Println(string(body))
|
||||
|
||||
}
|
47
newkey.go
Normal file
47
newkey.go
Normal file
@ -0,0 +1,47 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"log"
|
||||
"fmt"
|
||||
"os"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Load environment variables from .env file
|
||||
err := godotenv.Load()
|
||||
if err != nil {
|
||||
log.Fatal("Error loading .env file")
|
||||
}
|
||||
|
||||
token := os.Getenv("TOKEN")
|
||||
|
||||
// Make an HTTP request to api.discord-linux.com
|
||||
req, err := http.NewRequest("GET", "https://api.discord-linux.com/new-key", nil)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
req.Header.Set("Accept", "application/json")
|
||||
req.Header.Add("Content-Type", "Application/json")
|
||||
req.Header.Add("x-discord-linux-auth", token)
|
||||
|
||||
client := http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
fmt.Println("Status code: ", resp.StatusCode)
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Println(string(body))
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user