1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-11-24 08:57:03 -05:00

Parse Actor from star activity, Update function declaration order

This commit is contained in:
erik 2023-11-24 12:49:36 +01:00 committed by Michael Jerger
parent 3a938b6c3f
commit 566b3bc459

View file

@ -18,33 +18,14 @@ type Validatable interface { // ToDo: What is the right package for this interfa
}
type ActorID struct {
schema string
userId string
source forgefed.SourceType
schema string
path string
host string
port string // optional
}
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: validate_is_not_empty maybe not as an extra method
func (a ActorID) validate_is_not_empty(str string, field string) error {
@ -99,8 +80,28 @@ func (a ActorID) PanicIfInvalid() {
}
}
func ParseActorID(actor string) (ActorID, error) {
u, err := url.Parse(actor)
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
}
func ParseActorFromStarActivity(star *forgefed.Star) (ActorID, error) {
u, err := url.Parse(star.Actor.GetID().String())
// check if userID IRI is well formed url
if err != nil {