diff options
| author | Paul Buetow <paul@buetow.org> | 2024-11-19 22:46:05 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-11-19 22:46:05 +0200 |
| commit | 836d21a7c43f4ce84dfa1ada0552989be4a43ca9 (patch) | |
| tree | fe6dc637c2c916e10b1beff31d687edf0f994503 /internal/platforms | |
| parent | 1550fbf9c2b0602c4675f25cd92e389593894e58 (diff) | |
use of platform aliases
Diffstat (limited to 'internal/platforms')
| -rw-r--r-- | internal/platforms/platform.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/internal/platforms/platform.go b/internal/platforms/platform.go new file mode 100644 index 0000000..f899357 --- /dev/null +++ b/internal/platforms/platform.go @@ -0,0 +1,32 @@ +package platforms + +import ( + "fmt" + "strings" +) + +type Platform string + +var aliases = map[string]string{ + "linkedin": "linkedin", + "li": "linkedin", + "mastodon": "mastodon", + "ma": "mastodon", + "xcom": "xcom", + "x": "xcom", + "twitter": "xcom", + "tw": "xcom", +} + +func New(platformStr string) (Platform, error) { + var p Platform + name, ok := aliases[strings.ToLower(platformStr)] + if !ok { + return p, fmt.Errorf("no such platform: '%s'", platformStr) + } + return Platform(name), nil +} + +func (p Platform) String() string { + return string(p) +} |
