50 lines
1.0 KiB
Go
50 lines
1.0 KiB
Go
package fetch
|
|
|
|
import (
|
|
"context"
|
|
"net/url"
|
|
|
|
"forge.cadoles.com/arcad/edge/pkg/bus"
|
|
"github.com/oklog/ulid/v2"
|
|
)
|
|
|
|
const (
|
|
MessageNamespaceFetchRequest bus.MessageNamespace = "fetchRequest"
|
|
MessageNamespaceFetchResponse bus.MessageNamespace = "fetchResponse"
|
|
)
|
|
|
|
type MessageFetchRequest struct {
|
|
Context context.Context
|
|
RequestID string
|
|
URL *url.URL
|
|
RemoteAddr string
|
|
}
|
|
|
|
func (m *MessageFetchRequest) MessageNamespace() bus.MessageNamespace {
|
|
return MessageNamespaceFetchRequest
|
|
}
|
|
|
|
func NewMessageFetchRequest(ctx context.Context, remoteAddr string, url *url.URL) *MessageFetchRequest {
|
|
return &MessageFetchRequest{
|
|
Context: ctx,
|
|
RequestID: ulid.Make().String(),
|
|
RemoteAddr: remoteAddr,
|
|
URL: url,
|
|
}
|
|
}
|
|
|
|
type MessageFetchResponse struct {
|
|
RequestID string
|
|
Allow bool
|
|
}
|
|
|
|
func (m *MessageFetchResponse) MessageNamespace() bus.MessageNamespace {
|
|
return MessageNamespaceFetchResponse
|
|
}
|
|
|
|
func NewMessageFetchResponse(requestID string) *MessageFetchResponse {
|
|
return &MessageFetchResponse{
|
|
RequestID: requestID,
|
|
}
|
|
}
|