refactor: rename iot client to stateless gateway
This commit is contained in:
@@ -94,7 +94,7 @@ func dispatchIoTOutbox(ctx context.Context) {
|
||||
}
|
||||
payload["identity"] = outbox.CommandIdentity
|
||||
body, _ := json.Marshal(payload)
|
||||
dispatch, err := http.NewRequestWithContext(ctx, http.MethodPost, config.Spec.IoTAPI.ClientBaseURL+"/v1/device-commands", bytes.NewReader(body))
|
||||
dispatch, err := http.NewRequestWithContext(ctx, http.MethodPost, config.Spec.IoTAPI.GatewayBaseURL+"/v1/device-commands", bytes.NewReader(body))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
@@ -102,7 +102,7 @@ func dispatchIoTOutbox(ctx context.Context) {
|
||||
dispatch.Header.Set("X-Heqi-Iot-Token", config.Spec.IoTAPI.Token)
|
||||
dispatchResponse, err := client.Do(dispatch)
|
||||
if err != nil {
|
||||
completeIoTOutbox(ctx, client, outbox.Identity, false, 0, "IOT_CLIENT_UNAVAILABLE")
|
||||
completeIoTOutbox(ctx, client, outbox.Identity, false, 0, "IOT_GATEWAY_UNAVAILABLE")
|
||||
continue
|
||||
}
|
||||
var result struct {
|
||||
@@ -114,7 +114,7 @@ func dispatchIoTOutbox(ctx context.Context) {
|
||||
success := (status == http.StatusAccepted || status == http.StatusOK) && decodeErr == nil
|
||||
errorCode := ""
|
||||
if !success {
|
||||
errorCode = "IOT_CLIENT_REJECTED"
|
||||
errorCode = "IOT_GATEWAY_REJECTED"
|
||||
}
|
||||
completeIoTOutbox(ctx, client, outbox.Identity, success, result.PacketNumber, errorCode)
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ PaymentAPI:
|
||||
IntervalSeconds: 60
|
||||
IoTAPI:
|
||||
PlatformBaseURL: http://127.0.0.1:12426
|
||||
ClientBaseURL: http://127.0.0.1:12429
|
||||
GatewayBaseURL: http://127.0.0.1:12429
|
||||
Token: change-me-iot-internal-token
|
||||
IntervalMilliseconds: 500
|
||||
SecretKey: change-me-to-a-random-string
|
||||
|
||||
@@ -23,7 +23,7 @@ type PaymentAPIConfig struct {
|
||||
}
|
||||
type IoTAPIConfig struct {
|
||||
PlatformBaseURL string `yaml:"PlatformBaseURL"`
|
||||
ClientBaseURL string `yaml:"ClientBaseURL"`
|
||||
GatewayBaseURL string `yaml:"GatewayBaseURL"`
|
||||
Token string `yaml:"Token"`
|
||||
IntervalMilliseconds int `yaml:"IntervalMilliseconds"`
|
||||
}
|
||||
@@ -37,7 +37,7 @@ func New(srvKey string) {
|
||||
if Spec.PaymentAPI.BaseURL == "" || Spec.PaymentAPI.Token == "" || Spec.PaymentAPI.IntervalSeconds <= 0 {
|
||||
panic("PaymentAPI configuration is required")
|
||||
}
|
||||
if Spec.IoTAPI.PlatformBaseURL == "" || Spec.IoTAPI.ClientBaseURL == "" || Spec.IoTAPI.Token == "" || Spec.IoTAPI.IntervalMilliseconds <= 0 {
|
||||
if Spec.IoTAPI.PlatformBaseURL == "" || Spec.IoTAPI.GatewayBaseURL == "" || Spec.IoTAPI.Token == "" || Spec.IoTAPI.IntervalMilliseconds <= 0 {
|
||||
panic("IoTAPI configuration is required")
|
||||
}
|
||||
conf.PrintInfo(Spec.Addr)
|
||||
|
||||
Reference in New Issue
Block a user