OmitEmpty in JSON.

This commit is contained in:
Naoki Kosaka 2019-06-01 17:00:21 +09:00
parent 6e58f4a0b5
commit 8e27a857a9
3 changed files with 50 additions and 50 deletions

@ -16,34 +16,34 @@ import (
// PublicKey : Activity Certificate.
type PublicKey struct {
ID string `json:"id"`
Owner string `json:"owner"`
PublicKeyPem string `json:"publicKeyPem"`
ID string `json:"id,omitempty"`
Owner string `json:"owner,omitempty"`
PublicKeyPem string `json:"publicKeyPem,omitempty"`
}
//Endpoints : Contains SharedInbox address.
type Endpoints struct {
SharedInbox string `json:"sharedInbox"`
SharedInbox string `json:"sharedInbox,omitempty"`
}
// Image : Image Object.
type Image struct {
URL string `json:"url"`
URL string `json:"url,omitempty"`
}
// Actor : ActivityPub Actor.
type Actor struct {
Context interface{} `json:"@context"`
ID string `json:"id"`
Type string `json:"type"`
Name string `json:"name"`
PreferredUsername string `json:"preferredUsername"`
Summary string `json:"summary"`
Inbox string `json:"inbox"`
Endpoints *Endpoints `json:"endpoints"`
PublicKey PublicKey `json:"publicKey"`
Icon Image `json:"icon"`
Image Image `json:"image"`
Context interface{} `json:"@context,omitempty"`
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Name string `json:"name,omitempty"`
PreferredUsername string `json:"preferredUsername,omitempty"`
Summary string `json:"summary,omitempty"`
Inbox string `json:"inbox,omitempty"`
Endpoints *Endpoints `json:"endpoints,omitempty"`
PublicKey PublicKey `json:"publicKey,omitempty"`
Icon Image `json:"icon,omitempty"`
Image Image `json:"image,omitempty"`
}
// GenerateSelfKey : Generate relay Actor from Publickey.
@ -93,13 +93,13 @@ func (actor *Actor) RetrieveRemoteActor(url string, uaString string, cache *cach
// Activity : ActivityPub Activity.
type Activity struct {
Context interface{} `json:"@context"`
ID string `json:"id"`
Actor string `json:"actor"`
Type string `json:"type"`
Object interface{} `json:"object"`
To []string `json:"to"`
Cc []string `json:"cc"`
Context interface{} `json:"@context,omitempty"`
ID string `json:"id,omitempty"`
Actor string `json:"actor,omitempty"`
Type string `json:"type,omitempty"`
Object interface{} `json:"object,omitempty"`
To []string `json:"to,omitempty"`
Cc []string `json:"cc,omitempty"`
}
// GenerateResponse : Generate activity response.
@ -161,33 +161,33 @@ func (activity *Activity) NestedActivity() (*Activity, error) {
// ActivityObject : ActivityPub Activity.
type ActivityObject struct {
ID string `json:"id"`
Type string `json:"type"`
Name string `json:"name"`
Content string `json:"content"`
To []string `json:"to"`
Cc []string `json:"cc"`
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Name string `json:"name,omitempty"`
Content string `json:"content,omitempty"`
To []string `json:"to,omitempty"`
Cc []string `json:"cc,omitempty"`
}
// Signature : ActivityPub Header Signature.
type Signature struct {
Type string `json:"type"`
Creator string `json:"creator"`
Created string `json:"created"`
SignatureValue string `json:"signatureValue"`
Type string `json:"type,omitempty"`
Creator string `json:"creator,omitempty"`
Created string `json:"created,omitempty"`
SignatureValue string `json:"signatureValue,omitempty"`
}
// WebfingerLink : Webfinger Link Resource.
type WebfingerLink struct {
Rel string `json:"rel"`
Type string `json:"type"`
Href string `json:"href"`
Rel string `json:"rel,omitempty"`
Type string `json:"type,omitempty"`
Href string `json:"href,omitempty"`
}
// WebfingerResource : Webfinger Resource.
type WebfingerResource struct {
Subject string `json:"subject"`
Links []WebfingerLink `json:"links"`
Subject string `json:"subject,omitempty"`
Links []WebfingerLink `json:"links,omitempty"`
}
// GenerateFromActor : Generate Webfinger resource from Actor.

@ -31,10 +31,10 @@ func NewState(redisClient *redis.Client) RelayState {
type RelayState struct {
RedisClient *redis.Client
RelayConfig relayConfig `json:"relayConfig"`
LimitedDomains []string `json:"limitedDomains"`
BlockedDomains []string `json:"blockedDomains"`
Subscriptions []Subscription `json:"subscriptions"`
RelayConfig relayConfig `json:"relayConfig,omitempty"`
LimitedDomains []string `json:"limitedDomains,omitempty"`
BlockedDomains []string `json:"blockedDomains,omitempty"`
Subscriptions []Subscription `json:"subscriptions,omitempty"`
}
// Load : Refrash content from redis
@ -140,16 +140,16 @@ func (config *RelayState) SetLimitedDomain(domain string, value bool) {
// Subscription : Instance subscription information
type Subscription struct {
Domain string `json:"domain"`
InboxURL string `json:"inbox_url"`
ActivityID string `json:"activity_id"`
ActorID string `json:"actor_id"`
Domain string `json:"domain,omitempty"`
InboxURL string `json:"inbox_url,omitempty"`
ActivityID string `json:"activity_id,omitempty"`
ActorID string `json:"actor_id,omitempty"`
}
type relayConfig struct {
BlockService bool `json:"blockService"`
ManuallyAccept bool `json:"manuallyAccept"`
CreateAsAnnounce bool `json:"createAsAnnounce"`
BlockService bool `json:"blockService,omitempty"`
ManuallyAccept bool `json:"manuallyAccept,omitempty"`
CreateAsAnnounce bool `json:"createAsAnnounce,omitempty"`
}
func (config *relayConfig) load(redisClient *redis.Client) {

@ -1 +1 @@
{"RedisClient":{},"relayConfig":{"blockService":false,"manuallyAccept":false,"createAsAnnounce":false},"limitedDomains":null,"blockedDomains":null,"subscriptions":null}
{"RedisClient":{},"relayConfig":{}}