add api/v1/instance info handler + instance model (#18)

This commit is contained in:
Tobi Smethurst
2021-05-09 14:06:06 +02:00
committed by GitHub
parent 0cbab627c7
commit 3363e0ebdd
11 changed files with 222 additions and 22 deletions

View File

@ -0,0 +1,22 @@
package message
import (
"fmt"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
)
func (p *processor) InstanceGet(domain string) (*apimodel.Instance, ErrorWithCode) {
i := &gtsmodel.Instance{}
if err := p.db.GetWhere("domain", domain, i); err != nil {
return nil, NewErrorInternalError(fmt.Errorf("db error fetching instance %s: %s", p.config.Host, err))
}
ai, err := p.tc.InstanceToMasto(i)
if err != nil {
return nil, NewErrorInternalError(fmt.Errorf("error converting instance to api representation: %s", err))
}
return ai, nil
}