2021-10-08 12:39:31 +00:00
|
|
|
// SPDX-FileCopyrightText: 2021 The NGI Pointer Secure-Scuttlebutt Team of 2020/2021
|
|
|
|
//
|
2021-01-25 15:35:22 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
package whoami
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-03-11 17:40:33 +00:00
|
|
|
|
2022-11-07 09:18:13 +00:00
|
|
|
"github.com/ssbc/go-muxrpc/v2/typemux"
|
2021-01-25 15:35:22 +00:00
|
|
|
|
2022-11-07 09:18:13 +00:00
|
|
|
"github.com/ssbc/go-muxrpc/v2"
|
2021-05-21 07:27:12 +00:00
|
|
|
kitlog "go.mindeco.de/log"
|
|
|
|
"go.mindeco.de/log/level"
|
2021-01-25 15:35:22 +00:00
|
|
|
|
2022-11-07 09:18:13 +00:00
|
|
|
refs "github.com/ssbc/go-ssb-refs"
|
2021-01-25 15:35:22 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
method = muxrpc.Method{"whoami"}
|
|
|
|
)
|
|
|
|
|
2021-01-27 09:01:35 +00:00
|
|
|
func checkAndLog(log kitlog.Logger, err error) {
|
2021-01-25 15:35:22 +00:00
|
|
|
if err != nil {
|
2021-01-27 09:01:35 +00:00
|
|
|
level.Warn(log).Log("event", "faild to write panic file", "err", err)
|
2021-01-25 15:35:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-11 17:40:33 +00:00
|
|
|
func New(id refs.FeedRef) typemux.AsyncHandler {
|
|
|
|
return handler{id: id}
|
2021-01-25 15:35:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type handler struct {
|
2021-03-11 17:40:33 +00:00
|
|
|
id refs.FeedRef
|
2021-01-25 15:35:22 +00:00
|
|
|
}
|
|
|
|
|
2021-03-11 17:40:33 +00:00
|
|
|
func (h handler) HandleAsync(ctx context.Context, req *muxrpc.Request) (interface{}, error) {
|
2021-01-25 15:35:22 +00:00
|
|
|
type ret struct {
|
|
|
|
ID string `json:"id"`
|
|
|
|
}
|
|
|
|
|
2022-11-07 09:18:13 +00:00
|
|
|
return ret{h.id.String()}, nil
|
2021-01-25 15:35:22 +00:00
|
|
|
}
|