mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-06 00:09:37 +08:00
refactor: load env on running
This commit is contained in:
@@ -29,7 +29,6 @@ import (
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp/code"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/env"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/json"
|
||||
)
|
||||
|
||||
@@ -456,13 +455,14 @@ func DownloadFile(filePath string, fileUrl string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if env.EAPI_TOKEN != "" {
|
||||
eapiToken := os.Getenv("EAPI_TOKEN")
|
||||
if eapiToken != "" {
|
||||
if parsedURL.Host != "gtf-eapi-cn.bytedance.com" && parsedURL.Host != "gtf-eapi-cn.bytedance.net" {
|
||||
return errors.New("invalid domain: must be gtf-eapi-cn.bytedance.com")
|
||||
}
|
||||
// 添加自定义头部
|
||||
req.Header.Add("accessKey", "ies.vedem.video")
|
||||
req.Header.Add("token", env.EAPI_TOKEN)
|
||||
req.Header.Add("token", eapiToken)
|
||||
}
|
||||
|
||||
// 创建一个 HTTP 客户端并发送请求
|
||||
|
||||
14
hrp/internal/env/env.go
vendored
14
hrp/internal/env/env.go
vendored
@@ -6,20 +6,6 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
WDA_USB_DRIVER = os.Getenv("WDA_USB_DRIVER")
|
||||
WDA_LOCAL_PORT = os.Getenv("WDA_LOCAL_PORT")
|
||||
WDA_LOCAL_MJPEG_PORT = os.Getenv("WDA_LOCAL_MJPEG_PORT")
|
||||
VEDEM_IMAGE_URL = os.Getenv("VEDEM_IMAGE_URL")
|
||||
VEDEM_IMAGE_AK = os.Getenv("VEDEM_IMAGE_AK")
|
||||
VEDEM_IMAGE_SK = os.Getenv("VEDEM_IMAGE_SK")
|
||||
EAPI_TOKEN = os.Getenv("EAPI_TOKEN")
|
||||
DISABLE_GA = os.Getenv("DISABLE_GA")
|
||||
DISABLE_SENTRY = os.Getenv("DISABLE_SENTRY")
|
||||
PYPI_INDEX_URL = os.Getenv("PYPI_INDEX_URL")
|
||||
PATH = os.Getenv("PATH")
|
||||
)
|
||||
|
||||
const (
|
||||
ResultsDirName = "results"
|
||||
ScreenshotsDirName = "screenshots"
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
@@ -16,7 +17,6 @@ import (
|
||||
"github.com/rs/zerolog/log"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/env"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/version"
|
||||
)
|
||||
|
||||
@@ -195,7 +195,7 @@ func (g *GA4Client) SendEvent(event Event) error {
|
||||
}
|
||||
|
||||
func SendGA4Event(name string, params map[string]interface{}) {
|
||||
if env.DISABLE_GA == "true" {
|
||||
if os.Getenv("DISABLE_GA") == "true" {
|
||||
// do not send GA4 events in CI environment
|
||||
return
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@ package sdk
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/env"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/version"
|
||||
)
|
||||
|
||||
@@ -16,7 +16,7 @@ const (
|
||||
|
||||
func init() {
|
||||
// init sentry sdk
|
||||
if env.DISABLE_SENTRY == "true" {
|
||||
if os.Getenv("DISABLE_SENTRY") == "true" {
|
||||
return
|
||||
}
|
||||
err := sentry.Init(sentry.ClientOptions{
|
||||
|
||||
@@ -1 +1 @@
|
||||
v5.0.0-beta-2410112229
|
||||
v5.0.0-beta-2410161532
|
||||
|
||||
Reference in New Issue
Block a user