filter.go 679 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package tunnelstore
  2. import (
  3. "net/url"
  4. "time"
  5. "github.com/google/uuid"
  6. )
  7. const (
  8. TimeLayout = time.RFC3339
  9. )
  10. type Filter struct {
  11. queryParams url.Values
  12. }
  13. func NewFilter() *Filter {
  14. return &Filter{
  15. queryParams: url.Values{},
  16. }
  17. }
  18. func (f *Filter) ByName(name string) {
  19. f.queryParams.Set("name", name)
  20. }
  21. func (f *Filter) NoDeleted() {
  22. f.queryParams.Set("is_deleted", "false")
  23. }
  24. func (f *Filter) ByExistedAt(existedAt time.Time) {
  25. f.queryParams.Set("existed_at", existedAt.Format(TimeLayout))
  26. }
  27. func (f *Filter) ByTunnelID(tunnelID uuid.UUID) {
  28. f.queryParams.Set("uuid", tunnelID.String())
  29. }
  30. func (f Filter) encode() string {
  31. return f.queryParams.Encode()
  32. }