Skip to content
Snippets Groups Projects
Select Git revision
  • cd48596dc58875a27c616a288f3d375b56f812b5
  • master default protected
  • renovate/bootstrap-5.x
  • renovate/purgecss-webpack-plugin-7.x
  • renovate/mini-css-extract-plugin-2.x
  • renovate/html-webpack-plugin-5.x
  • renovate/golang-1.x
  • renovate/css-loader-6.x
8 results

convert.go

Blame
    • ale's avatar
      0def9013
      Switch to a self-hosted binary, add graph-related code · 0def9013
      ale authored
      The app is now self-hosted instead of relying on the static-content
      standalone server, so we can eventually add dynamic code for graph
      serving.
      
      The static content serving has improved, with more consistent cache
      header management, as well as the capability of serving pre-compressed
      content.
      
      Additional code to implement the generation of dependency (flow)
      graphs in dot format was added (not hooked to the HTTP server yet).
      0def9013
      History
      Switch to a self-hosted binary, add graph-related code
      ale authored
      The app is now self-hosted instead of relying on the static-content
      standalone server, so we can eventually add dynamic code for graph
      serving.
      
      The static content serving has improved, with more consistent cache
      header management, as well as the capability of serving pre-compressed
      content.
      
      Additional code to implement the generation of dependency (flow)
      graphs in dot format was added (not hooked to the HTTP server yet).
    convert.go 1.27 KiB
    package schema
    
    import (
    	"encoding/json"
    	"fmt"
    	"os"
    
    	dashschema "git.autistici.org/ai3/tools/float-dashboard/schema/dash"
    	floatschema "git.autistici.org/ai3/tools/float-dashboard/schema/float"
    	"gopkg.in/yaml.v3"
    )
    
    func loadYAML(path string, obj interface{}) error {
    	f, err := os.Open(path)
    	if err != nil {
    		return err
    	}
    	defer f.Close()
    
    	return yaml.NewDecoder(f).Decode(obj)
    }
    
    func LoadFloatServices(svcFile, leadersFile string) (map[string]*floatschema.Service, error) {
    	// Load the service definitions and the leaders map.
    	var svcmap map[string]*floatschema.Service
    	if err := loadYAML(svcFile, &svcmap); err != nil {
    		return nil, err
    	}
    
    	var leaders map[string]string
    	if err := loadYAML(leadersFile, &leaders); err != nil {
    		return nil, err
    	}
    
    	// Map back leaders into services.
    	for svcname, leader := range leaders {
    		if _, ok := svcmap[svcname]; !ok {
    			return nil, fmt.Errorf("leaders file references service '%s' which does not exist!", svcname)
    		}
    		svcmap[svcname].MasterHost = leader
    	}
    
    	return svcmap, nil
    }
    
    func Convert(svcmap map[string]*floatschema.Service, publicDomain string) ([]byte, error) {
    	out := make(map[string]*dashschema.Service)
    	for name, fsvc := range svcmap {
    		out[name] = dashschema.FromFloat(fsvc, publicDomain)
    	}
    	return json.Marshal(out)
    }