tagger/internal/service/service.go
Matthew Rich 14fda44c41
Some checks failed
Lint / golangci-lint (push) Failing after 10m25s
Declarative Tests / test (push) Failing after 1m59s
add artifacts
2024-04-04 13:37:54 -07:00

54 lines
1.2 KiB
Go

// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
package service
import (
"errors"
_ "io"
"context"
_ "fmt"
_ "net/http"
_ "encoding/json"
_ "github.com/gin-gonic/gin"
)
type Service struct {
connector DataConnector
}
func NewService() *Service {
return &Service{}
}
func (s *Service) Tags(ctx context.Context) []string {
return s.connector.Tags(ctx)
}
func (s *Service) Query(ctx context.Context, terms []string) []string {
result, _ := s.connector.Query(ctx, terms)
return result
}
func (s *Service) UseDataConnector(ctx context.Context, d DataConnector) error {
if d != nil && d.Connected(ctx) {
s.connector = d
return nil
}
return errors.New("The connector is not connected")
}
func (s *Service) AddTag(ctx context.Context, TagName string, Resource string) error {
return s.connector.AddTag(ctx, TagName, Resource)
}
func (s *Service) ResourceTags(ctx context.Context, Resource string) []string {
tags := s.connector.Tags(ctx)
results := make([]string, 0, len(tags)/10 )
for _,t := range(s.connector.Tags(ctx)) {
if(s.connector.ResourceHasTag(ctx, Resource, t)) {
results = append(results, t)
}
}
return results
}