code.gitea.io/gitea@v1.22.3/modules/setting/config/getter.go (about)

     1  // Copyright 2023 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package config
     5  
     6  import (
     7  	"context"
     8  	"sync"
     9  )
    10  
    11  var getterMu sync.RWMutex
    12  
    13  type CfgSecKeyGetter interface {
    14  	GetValue(sec, key string) (v string, has bool)
    15  }
    16  
    17  var cfgSecKeyGetterInternal CfgSecKeyGetter
    18  
    19  func SetCfgSecKeyGetter(p CfgSecKeyGetter) {
    20  	getterMu.Lock()
    21  	cfgSecKeyGetterInternal = p
    22  	getterMu.Unlock()
    23  }
    24  
    25  func GetCfgSecKeyGetter() CfgSecKeyGetter {
    26  	getterMu.RLock()
    27  	defer getterMu.RUnlock()
    28  	return cfgSecKeyGetterInternal
    29  }
    30  
    31  type DynKeyGetter interface {
    32  	GetValue(ctx context.Context, key string) (v string, has bool)
    33  	GetRevision(ctx context.Context) int
    34  	InvalidateCache()
    35  }
    36  
    37  var dynKeyGetterInternal DynKeyGetter
    38  
    39  func SetDynGetter(p DynKeyGetter) {
    40  	getterMu.Lock()
    41  	dynKeyGetterInternal = p
    42  	getterMu.Unlock()
    43  }
    44  
    45  func GetDynGetter() DynKeyGetter {
    46  	getterMu.RLock()
    47  	defer getterMu.RUnlock()
    48  	return dynKeyGetterInternal
    49  }