golang.zx2c4.com/wireguard/windows@v0.5.4-0.20230123132234-dcc0eb72a04b/conf/storewatcher.go (about)

     1  /* SPDX-License-Identifier: MIT
     2   *
     3   * Copyright (C) 2019-2022 WireGuard LLC. All Rights Reserved.
     4   */
     5  
     6  package conf
     7  
     8  type StoreCallback struct {
     9  	cb func()
    10  }
    11  
    12  var storeCallbacks = make(map[*StoreCallback]bool)
    13  
    14  func RegisterStoreChangeCallback(cb func()) *StoreCallback {
    15  	startWatchingConfigDir()
    16  	cb()
    17  	s := &StoreCallback{cb}
    18  	storeCallbacks[s] = true
    19  	return s
    20  }
    21  
    22  func (cb *StoreCallback) Unregister() {
    23  	delete(storeCallbacks, cb)
    24  }