Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

42 lignes
1.2 KiB

  1. package location
  2. import (
  3. "context"
  4. "crypto/tls"
  5. "net/http"
  6. "github.com/AFASystems/presence/internal/pkg/apiclient"
  7. "github.com/AFASystems/presence/internal/pkg/config"
  8. "github.com/AFASystems/presence/internal/pkg/model"
  9. )
  10. // Inferencer returns inferred positions (e.g. from an AI/ML service).
  11. type Inferencer interface {
  12. Infer(ctx context.Context, cfg *config.Config) (model.PositionResponse, error)
  13. }
  14. // DefaultInferencer uses apiclient to get token and call the inference API.
  15. type DefaultInferencer struct {
  16. Client *http.Client
  17. }
  18. // NewDefaultInferencer creates an inferencer with optional TLS skip verify (e.g. from config.TLSInsecureSkipVerify).
  19. func NewDefaultInferencer(skipTLSVerify bool) *DefaultInferencer {
  20. tr := &http.Transport{}
  21. if skipTLSVerify {
  22. tr.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
  23. }
  24. return &DefaultInferencer{
  25. Client: &http.Client{Transport: tr},
  26. }
  27. }
  28. // Infer gets a token and calls the inference API.
  29. func (d *DefaultInferencer) Infer(ctx context.Context, cfg *config.Config) (model.PositionResponse, error) {
  30. token, err := apiclient.GetToken(ctx, cfg, d.Client)
  31. if err != nil {
  32. return model.PositionResponse{}, err
  33. }
  34. return apiclient.InferPosition(token, d.Client, cfg)
  35. }