From 91baf2be32471779ffbf42016c519e694c48a18e Mon Sep 17 00:00:00 2001 From: erik Date: Thu, 23 Nov 2023 17:03:24 +0100 Subject: [PATCH] Add get functions for userId and HostAndPort --- models/activitypub/actor.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/models/activitypub/actor.go b/models/activitypub/actor.go index f27ad1bf38..312edd3bdc 100644 --- a/models/activitypub/actor.go +++ b/models/activitypub/actor.go @@ -3,6 +3,7 @@ package activitypub import ( "fmt" "net/url" + "strconv" "strings" ) @@ -29,6 +30,26 @@ func (a ActorID) validate_is_not_empty(str string, field string) error { return nil } +func (a ActorID) GetUserId() int { + result, err := strconv.Atoi(a.userId) + + if err != nil { + panic(err) + } + + return result +} + +// Returns the combination of host:port if port exists, host otherwise +func (a ActorID) GetHostAndPort() string { + + if a.port != "" { + return strings.Join([]string{a.host, a.port}, ":") + } + + return a.host +} + // TODO: Align validation-api to example from dda-devops-build func (a ActorID) Validate() error {