Skip to content
Snippets Groups Projects
Select Git revision
  • 6abdc13c87f936cf7f45f517b346b84693a4b1d3
  • release default
  • master protected
  • hotfix/gtnNoToken
  • XX-4441
  • Jakub/rootless-CI
  • jonah/refactorProviders
  • Ace/Huawei
  • AceVentura/AccountBackup
  • hotfix/delete-error
  • waitingRoundsRewrite
  • dev
  • quantumSecure
  • hotfix/ratelimit
  • fullRateLimit
  • XX-3564/TlsCipherSuite
  • hotfix/notifications-db
  • hotfix/groupNotification
  • Project/LastMile
  • notls
  • url-repo-rename
  • v2.3.0
  • v2.2.0
  • v2.1.0
  • v2.0.0
  • v1.0.0
26 results

go.sum

Blame
  • This project manages its dependencies using Go Modules. Learn more
    params.go 2.71 KiB
    ////////////////////////////////////////////////////////////////////////////////
    // Copyright © 2020 xx network SEZC                                           //
    //                                                                            //
    // Use of this source code is governed by a license that can be found in the  //
    // LICENSE file                                                               //
    ////////////////////////////////////////////////////////////////////////////////
    
    package message
    
    import (
    	"encoding/json"
    	"time"
    )
    
    // Params contains the parameters for the message package.
    type Params struct {
    	MessageReceptionBuffLen        uint
    	MessageReceptionWorkerPoolSize uint
    	MaxChecksInProcessMessage      uint
    	InProcessMessageWait           time.Duration
    	RealtimeOnly                   bool
    }
    
    // paramsDisk will be the marshal-able and umarshal-able object.
    type paramsDisk struct {
    	MessageReceptionBuffLen        uint
    	MessageReceptionWorkerPoolSize uint
    	MaxChecksInProcessMessage      uint
    	InProcessMessageWait           time.Duration
    	RealtimeOnly                   bool
    }
    
    // GetDefaultParams returns a Params object containing the
    // default parameters.
    func GetDefaultParams() Params {
    	return Params{
    		MessageReceptionBuffLen:        500,
    		MessageReceptionWorkerPoolSize: 4,
    		MaxChecksInProcessMessage:      10,
    		InProcessMessageWait:           15 * time.Minute,
    		RealtimeOnly:                   false,
    	}
    }
    
    // GetParameters returns the default Params, or override with given
    // parameters, if set.
    func GetParameters(params string) (Params, error) {
    	p := GetDefaultParams()
    	if len(params) > 0 {
    		err := json.Unmarshal([]byte(params), &p)
    		if err != nil {
    			return Params{}, err
    		}
    	}
    	return p, nil
    }
    
    // MarshalJSON adheres to the json.Marshaler interface.
    func (r Params) MarshalJSON() ([]byte, error) {
    	pDisk := paramsDisk{
    		MessageReceptionBuffLen:        r.MessageReceptionBuffLen,
    		MessageReceptionWorkerPoolSize: r.MessageReceptionWorkerPoolSize,
    		MaxChecksInProcessMessage:      r.MaxChecksInProcessMessage,
    		InProcessMessageWait:           r.InProcessMessageWait,
    		RealtimeOnly:                   r.RealtimeOnly,
    	}
    
    	return json.Marshal(&pDisk)
    
    }
    
    // UnmarshalJSON adheres to the json.Unmarshaler interface.
    func (r *Params) UnmarshalJSON(data []byte) error {
    	pDisk := paramsDisk{}
    	err := json.Unmarshal(data, &pDisk)
    	if err != nil {
    		return err
    	}
    
    	*r = Params{
    		MessageReceptionBuffLen:        pDisk.MessageReceptionBuffLen,
    		MessageReceptionWorkerPoolSize: pDisk.MessageReceptionWorkerPoolSize,
    		MaxChecksInProcessMessage:      pDisk.MaxChecksInProcessMessage,
    		InProcessMessageWait:           pDisk.InProcessMessageWait,
    		RealtimeOnly:                   pDisk.RealtimeOnly,
    	}
    
    	return nil
    }