diff options
| author | 2025-04-09 16:32:13 +0000 | |
|---|---|---|
| committer | 2025-04-09 17:32:13 +0100 | |
| commit | b1a4d54c14647827aaf3c8174e2896b12d0f9608 (patch) | |
| tree | a66cbe831407565a6b7af421c5e659e08fd7306c /internal/config/types.go | |
| parent | [bugfix] Fix a couple accessibility issues with `:focus` elements (#3979) (diff) | |
| download | gotosocial-b1a4d54c14647827aaf3c8174e2896b12d0f9608.tar.xz | |
[chore] add IPPrefixes type so we don't need separate rate limit parsed field (#3982)
* add IPPrefixes type so we don't need separate rate limit parsed field
* sshhhh please linter, mommy's working
Diffstat (limited to 'internal/config/types.go')
| -rw-r--r-- | internal/config/types.go | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/internal/config/types.go b/internal/config/types.go new file mode 100644 index 000000000..c2296975f --- /dev/null +++ b/internal/config/types.go @@ -0,0 +1,62 @@ +// GoToSocial +// Copyright (C) GoToSocial Authors admin@gotosocial.org +// SPDX-License-Identifier: AGPL-3.0-or-later +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. + +package config + +import ( + "net/netip" + + "codeberg.org/gruf/go-byteutil" +) + +// IPPrefixes is a type-alias for []netip.Prefix +// to allow parsing by CLI "flag"-like utilities. +type IPPrefixes []netip.Prefix + +func (p *IPPrefixes) Set(in string) error { + prefix, err := netip.ParsePrefix(in) + if err != nil { + return err + } + (*p) = append((*p), prefix) + return nil +} + +func (p *IPPrefixes) String() string { + if p == nil || len(*p) == 0 { + return "" + } + var buf byteutil.Buffer + for _, prefix := range *p { + str := prefix.String() + buf.B = append(buf.B, str...) + buf.B = append(buf.B, ',') + } + buf.Truncate(1) + return buf.String() +} + +func (p *IPPrefixes) Strings() []string { + if p == nil || len(*p) == 0 { + return nil + } + strs := make([]string, len(*p)) + for i, prefix := range *p { + strs[i] = prefix.String() + } + return strs +} |
