mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-11-26 05:36:38 +00:00
moving stuff around, stubbing interfaces
This commit is contained in:
parent
338af00e7b
commit
9a79d176c9
|
@ -26,7 +26,7 @@
|
||||||
"github.com/gotosocial/gotosocial/internal/config"
|
"github.com/gotosocial/gotosocial/internal/config"
|
||||||
"github.com/gotosocial/gotosocial/internal/db"
|
"github.com/gotosocial/gotosocial/internal/db"
|
||||||
"github.com/gotosocial/gotosocial/internal/log"
|
"github.com/gotosocial/gotosocial/internal/log"
|
||||||
"github.com/gotosocial/gotosocial/internal/server"
|
"github.com/gotosocial/gotosocial/internal/gotosocial"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
|
@ -105,7 +105,7 @@ func main() {
|
||||||
Name: "start",
|
Name: "start",
|
||||||
Usage: "start the gotosocial server",
|
Usage: "start the gotosocial server",
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
return runAction(c, server.Run)
|
return runAction(c, gotosocial.Run)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
6
internal/cache/cache.go
vendored
6
internal/cache/cache.go
vendored
|
@ -17,3 +17,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package cache
|
package cache
|
||||||
|
|
||||||
|
// Cache defines an in-memory cache that is safe to be wiped when the application is restarted
|
||||||
|
type Cache interface {
|
||||||
|
Store(k string, v interface{}) error
|
||||||
|
Fetch(k string) (interface{}, error)
|
||||||
|
}
|
||||||
|
|
|
@ -16,12 +16,12 @@
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package api
|
package client
|
||||||
|
|
||||||
// API is the client API exposed to the outside world for access by front-ends; this is distinct from the federation API
|
// API is the client API exposed to the outside world for access by front-ends; this is distinct from the federation API
|
||||||
type API interface {
|
type API interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
// api implements Api interface
|
// api implements ClientAPI interface
|
||||||
type api struct {
|
type api struct {
|
||||||
}
|
}
|
|
@ -16,16 +16,4 @@
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package api
|
package client
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
)
|
|
||||||
|
|
||||||
func statusGet(c *gin.Context) {
|
|
||||||
c.HTML(http.StatusOK, "index.tmpl", gin.H{
|
|
||||||
"title": "Posts",
|
|
||||||
})
|
|
||||||
}
|
|
|
@ -16,4 +16,4 @@
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package server
|
package client
|
|
@ -1,3 +1,21 @@
|
||||||
|
/*
|
||||||
|
GoToSocial
|
||||||
|
Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
|
||||||
|
|
||||||
|
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
|
package config
|
||||||
|
|
||||||
// DBConfig provides configuration options for the database connection
|
// DBConfig provides configuration options for the database connection
|
||||||
|
|
|
@ -114,7 +114,7 @@ func newPostgresService(ctx context.Context, c *config.Config, log *logrus.Entry
|
||||||
CreatedAt: time.Now(),
|
CreatedAt: time.Now(),
|
||||||
UpdatedAt: time.Now(),
|
UpdatedAt: time.Now(),
|
||||||
}
|
}
|
||||||
if _, err := conn.Model(note).Returning("id").Insert(); err != nil {
|
if _, err := conn.WithContext(ctx).Model(note).Returning("id").Insert(); err != nil {
|
||||||
cancel()
|
cancel()
|
||||||
return nil, fmt.Errorf("db insert error: %s", err)
|
return nil, fmt.Errorf("db insert error: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,82 +31,82 @@
|
||||||
)
|
)
|
||||||
|
|
||||||
func New(db db.DB) pub.FederatingActor {
|
func New(db db.DB) pub.FederatingActor {
|
||||||
fs := &FederationService{}
|
fa := &API{}
|
||||||
return pub.NewFederatingActor(fs, fs, db, fs)
|
return pub.NewFederatingActor(fa, fa, db, fa)
|
||||||
}
|
}
|
||||||
|
|
||||||
type FederationService struct {
|
type API struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AuthenticateGetInbox determines whether the request is for a GET call to the Actor's Inbox.
|
// AuthenticateGetInbox determines whether the request is for a GET call to the Actor's Inbox.
|
||||||
func (fs *FederationService) AuthenticateGetInbox(ctx context.Context, w http.ResponseWriter, r *http.Request) (context.Context, bool, error) {
|
func (fa *API) AuthenticateGetInbox(ctx context.Context, w http.ResponseWriter, r *http.Request) (context.Context, bool, error) {
|
||||||
// TODO
|
// TODO
|
||||||
return nil, false, nil
|
return nil, false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AuthenticateGetOutbox determines whether the request is for a GET call to the Actor's Outbox.
|
// AuthenticateGetOutbox determines whether the request is for a GET call to the Actor's Outbox.
|
||||||
func (fs *FederationService) AuthenticateGetOutbox(ctx context.Context, w http.ResponseWriter, r *http.Request) (context.Context, bool, error) {
|
func (fa *API) AuthenticateGetOutbox(ctx context.Context, w http.ResponseWriter, r *http.Request) (context.Context, bool, error) {
|
||||||
// TODO
|
// TODO
|
||||||
return nil, false, nil
|
return nil, false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetOutbox returns a proper paginated view of the Outbox for serving in a response.
|
// GetOutbox returns a proper paginated view of the Outbox for serving in a response.
|
||||||
func (fs *FederationService) GetOutbox(ctx context.Context, r *http.Request) (vocab.ActivityStreamsOrderedCollectionPage, error) {
|
func (fa *API) GetOutbox(ctx context.Context, r *http.Request) (vocab.ActivityStreamsOrderedCollectionPage, error) {
|
||||||
// TODO
|
// TODO
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTransport returns a new pub.Transport for federating with peer software.
|
// NewTransport returns a new pub.Transport for federating with peer software.
|
||||||
func (fs *FederationService) NewTransport(ctx context.Context, actorBoxIRI *url.URL, gofedAgent string) (pub.Transport, error) {
|
func (fa *API) NewTransport(ctx context.Context, actorBoxIRI *url.URL, gofedAgent string) (pub.Transport, error) {
|
||||||
// TODO
|
// TODO
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *FederationService) PostInboxRequestBodyHook(ctx context.Context, r *http.Request, activity pub.Activity) (context.Context, error) {
|
func (fa *API) PostInboxRequestBodyHook(ctx context.Context, r *http.Request, activity pub.Activity) (context.Context, error) {
|
||||||
// TODO
|
// TODO
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *FederationService) AuthenticatePostInbox(ctx context.Context, w http.ResponseWriter, r *http.Request) (context.Context, bool, error) {
|
func (fa *API) AuthenticatePostInbox(ctx context.Context, w http.ResponseWriter, r *http.Request) (context.Context, bool, error) {
|
||||||
// TODO
|
// TODO
|
||||||
return nil, false, nil
|
return nil, false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *FederationService) Blocked(ctx context.Context, actorIRIs []*url.URL) (bool, error) {
|
func (fa *API) Blocked(ctx context.Context, actorIRIs []*url.URL) (bool, error) {
|
||||||
// TODO
|
// TODO
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *FederationService) FederatingCallbacks(ctx context.Context) (pub.FederatingWrappedCallbacks, []interface{}, error) {
|
func (fa *API) FederatingCallbacks(ctx context.Context) (pub.FederatingWrappedCallbacks, []interface{}, error) {
|
||||||
// TODO
|
// TODO
|
||||||
return pub.FederatingWrappedCallbacks{}, nil, nil
|
return pub.FederatingWrappedCallbacks{}, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *FederationService) DefaultCallback(ctx context.Context, activity pub.Activity) error {
|
func (fa *API) DefaultCallback(ctx context.Context, activity pub.Activity) error {
|
||||||
// TODO
|
// TODO
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *FederationService) MaxInboxForwardingRecursionDepth(ctx context.Context) int {
|
func (fa *API) MaxInboxForwardingRecursionDepth(ctx context.Context) int {
|
||||||
// TODO
|
// TODO
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *FederationService) MaxDeliveryRecursionDepth(ctx context.Context) int {
|
func (fa *API) MaxDeliveryRecursionDepth(ctx context.Context) int {
|
||||||
// TODO
|
// TODO
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *FederationService) FilterForwarding(ctx context.Context, potentialRecipients []*url.URL, a pub.Activity) ([]*url.URL, error) {
|
func (fa *API) FilterForwarding(ctx context.Context, potentialRecipients []*url.URL, a pub.Activity) ([]*url.URL, error) {
|
||||||
// TODO
|
// TODO
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *FederationService) GetInbox(ctx context.Context, r *http.Request) (vocab.ActivityStreamsOrderedCollectionPage, error) {
|
func (fa *API) GetInbox(ctx context.Context, r *http.Request) (vocab.ActivityStreamsOrderedCollectionPage, error) {
|
||||||
// TODO
|
// TODO
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *FederationService) Now() time.Time {
|
func (fa *API) Now() time.Time {
|
||||||
return time.Now()
|
return time.Now()
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package server
|
package gotosocial
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -31,7 +31,7 @@
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Run starts the gotosocial server
|
// Run creates and starts a gotosocial server
|
||||||
var Run action.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error {
|
var Run action.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error {
|
||||||
dbService, err := db.New(ctx, c, log)
|
dbService, err := db.New(ctx, c, log)
|
||||||
if err != nil {
|
if err != nil {
|
60
internal/gotosocial/gotosocial.go
Normal file
60
internal/gotosocial/gotosocial.go
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
/*
|
||||||
|
GoToSocial
|
||||||
|
Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
|
||||||
|
|
||||||
|
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 gotosocial
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/go-fed/activity/pub"
|
||||||
|
"github.com/gotosocial/gotosocial/internal/cache"
|
||||||
|
"github.com/gotosocial/gotosocial/internal/client"
|
||||||
|
"github.com/gotosocial/gotosocial/internal/config"
|
||||||
|
"github.com/gotosocial/gotosocial/internal/db"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Gotosocial interface {
|
||||||
|
Start(context.Context) error
|
||||||
|
Stop(context.Context) error
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(db db.DB, cache cache.Cache, clientAPI client.API, federationAPI pub.FederatingActor, config *config.Config) (Gotosocial, error) {
|
||||||
|
return &gotosocial{
|
||||||
|
db: db,
|
||||||
|
cache: cache,
|
||||||
|
clientAPI: clientAPI,
|
||||||
|
federationAPI: federationAPI,
|
||||||
|
config: config,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type gotosocial struct {
|
||||||
|
db db.DB
|
||||||
|
cache cache.Cache
|
||||||
|
clientAPI client.API
|
||||||
|
federationAPI pub.FederatingActor
|
||||||
|
config *config.Config
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gts *gotosocial) Start(ctx context.Context) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gts *gotosocial) Stop(ctx context.Context) error {
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -16,34 +16,9 @@
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package api
|
package media
|
||||||
|
|
||||||
import "github.com/gin-gonic/gin"
|
// API provides an interface for parsing, storing, and retrieving media objects like photos and videos
|
||||||
|
type API interface {
|
||||||
|
|
||||||
// Router provides the http routes used by the API
|
|
||||||
type Router interface {
|
|
||||||
Route() error
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewRouter returns a new router
|
|
||||||
func NewRouter() Router {
|
|
||||||
return &router{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// router implements the router interface
|
|
||||||
type router struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *router) Route() error {
|
|
||||||
ginRouter := gin.Default()
|
|
||||||
ginRouter.LoadHTMLGlob("web/template/*")
|
|
||||||
|
|
||||||
apiGroup := ginRouter.Group("/api")
|
|
||||||
|
|
||||||
v1 := apiGroup.Group("/v1")
|
|
||||||
|
|
||||||
statusesGroup := v1.Group("/statuses")
|
|
||||||
statusesGroup.GET(":id", statusGet)
|
|
||||||
err := ginRouter.Run()
|
|
||||||
return err
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue