52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
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
|
|
}
|