Initial cloud-services repo - gateway service + pkg modules

This commit is contained in:
Chris Rai
2026-01-30 23:14:52 -05:00
commit fbb820d7b3
1037 changed files with 171318 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
package websocket
import (
"net/http"
"strings"
)
// ParseDBCFromRequest retrieves DBC version from the "fisker-dbc" field
//
// located in header of request
func ParseDBCFromRequest(r *http.Request) string {
return r.Header.Get("Fisker-Dbc-Sha256")
}
func ParseICCIDFromRequest(r *http.Request) (string, error) {
iccid := strings.TrimSpace(r.Header.Get("X-ICCID"))
// ok, err := validator.ValidateICCIDSimple(iccid)
// if err != nil {
// return iccid, err
// } else if !ok {
// return iccid, errors.Errorf("%s failed to pass ICCID validation", iccid)
// }
return iccid, nil
}
// ParseDeviceAndVersionFromRequest parses device type and version
//
// of client from User-Agent field in header
func ParseDeviceAndVersionFromRequest(r *http.Request) (string, string) {
var device string
var version string
userAgent := r.Header.Get("User-Agent")
specs := strings.Split(userAgent, " ")
device = strings.ToLower(specs[0])
switch len(specs) {
case 5:
version = specs[3]
case 4:
version = specs[2]
case 2:
version = specs[1]
}
return device, version
}