github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/pkg/config/scrapeGroup.go (about)

     1  // Copyright 2021 The TrueBlocks Authors. All rights reserved.
     2  // Use of this source code is governed by a license that can
     3  // be found in the LICENSE file.
     4  
     5  package config
     6  
     7  import (
     8  	"strconv"
     9  
    10  	"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/configtypes"
    11  )
    12  
    13  // GetScrape returns the scraper settings per chain
    14  func GetScrape(chain string) configtypes.ScrapeSettings {
    15  	return GetRootConfig().Chains[chain].Scrape
    16  }
    17  
    18  func SetScrapeArgs(chain string, args map[string]string) {
    19  	ch := trueBlocksConfig.Chains[chain]
    20  
    21  	empty := configtypes.ScrapeSettings{}
    22  	if trueBlocksConfig.Chains[chain].Scrape == empty {
    23  		ch.Scrape = GetScrape(chain)
    24  
    25  	} else {
    26  		settings := trueBlocksConfig.Chains[chain].Scrape
    27  		for key, value := range args {
    28  			switch key {
    29  			case "appsPerChunk":
    30  				settings.AppsPerChunk, _ = strconv.ParseUint(value, 0, 64)
    31  			case "snapToGrid":
    32  				settings.SnapToGrid, _ = strconv.ParseUint(value, 0, 64)
    33  			case "firstSnap":
    34  				settings.FirstSnap, _ = strconv.ParseUint(value, 0, 64)
    35  			case "unripeDist":
    36  				settings.UnripeDist, _ = strconv.ParseUint(value, 0, 64)
    37  			case "channelCount":
    38  				settings.ChannelCount, _ = strconv.ParseUint(value, 0, 64)
    39  			case "allowMissing":
    40  				settings.AllowMissing = true
    41  			}
    42  		}
    43  		ch.Scrape = settings
    44  	}
    45  
    46  	trueBlocksConfig.Chains[chain] = ch
    47  }