use server infos from config file
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 8s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 8s
This commit is contained in:
@@ -199,6 +199,19 @@ func DeleteData(target config.Server, path, id string) {
|
||||
}
|
||||
}
|
||||
|
||||
func PushData(target config.Server, path string, data any, result any) (response *resty.Response, err error) {
|
||||
url := fmt.Sprintf("%s/%s/%s", target.Url, config.Config.ApiVersion, path)
|
||||
client := resty.New()
|
||||
token := GetToken(client, target)
|
||||
response, err = client.R().
|
||||
SetBody(data).
|
||||
SetAuthToken(token).
|
||||
SetHeader("Accept", "application/json").
|
||||
SetResult(result).
|
||||
Post(url)
|
||||
return response, err
|
||||
}
|
||||
|
||||
func UpdateData(target config.Server, path string, v any) {
|
||||
client := resty.New()
|
||||
client.SetLoggerWarnLevel(true)
|
||||
|
||||
@@ -10,11 +10,6 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"resty.dev/v3"
|
||||
)
|
||||
|
||||
var (
|
||||
servername string
|
||||
)
|
||||
|
||||
var addLinksCmd = &cobra.Command{
|
||||
@@ -31,18 +26,11 @@ var addLinksCmd = &cobra.Command{
|
||||
slog.Warn("add links failed", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
client := resty.New()
|
||||
localServer := config.Config.Server[servername]
|
||||
token := api.GetToken(client, localServer)
|
||||
localServer := config.Config.Server[config.ServerName]
|
||||
for _, line := range lines {
|
||||
lofiAdd := models.MediaLofiAdd{Url: line}
|
||||
addResult := &models.MediaLoFi{}
|
||||
response, err := client.R().
|
||||
SetBody(lofiAdd).
|
||||
SetAuthToken(token).
|
||||
SetHeader("Accept", "application/json").
|
||||
SetResult(addResult).
|
||||
Post("http://localhost:8550/api/v1/media/lofis")
|
||||
response, err := api.PushData(localServer, "media/lofis", lofiAdd, addResult)
|
||||
if err != nil {
|
||||
slog.Info("Add Lofi", "error", err.Error())
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ func init() {
|
||||
viper.BindPFlag("config", rootCmd.PersistentFlags().Lookup("config"))
|
||||
exportCmd.Flags().StringVarP(&config.ServerName, "servername", "s", "local", "Define server to get Kontor items")
|
||||
updateTitleCmd.Flags().StringVarP(&config.ServerName, "servername", "s", "local", "Define server to get Kontor items")
|
||||
addLinksCmd.Flags().StringVarP(&config.ServerName, "servername", "s", "local", "Define server to get Kontor items")
|
||||
viper.BindPFlag("server", exportCmd.PersistentFlags().Lookup("server"))
|
||||
cobra.OnInitialize(config.InitCliConfig)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user