...

Source file src/github.com/GoogleCloudPlatform/k8s-config-connector/config/servicemappings/embed.go

Documentation: github.com/GoogleCloudPlatform/k8s-config-connector/config/servicemappings

     1  // Copyright 2022 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package servicemappings
    16  
    17  import (
    18  	"embed"
    19  	"fmt"
    20  )
    21  
    22  //go:embed *.yaml
    23  var servicemappings embed.FS
    24  
    25  func ServiceMapping(key string) ([]byte, error) {
    26  	b, err := servicemappings.ReadFile(key)
    27  	if err != nil {
    28  		return nil, fmt.Errorf("error reading embedded file %q: %w", key, err)
    29  	}
    30  	return b, nil
    31  }
    32  
    33  func AllKeys() ([]string, error) {
    34  	p := "."
    35  	entries, err := servicemappings.ReadDir(p)
    36  	if err != nil {
    37  		return nil, fmt.Errorf("error reading embedded directory %q: %w", p, err)
    38  	}
    39  	var keys []string
    40  	for _, entry := range entries {
    41  		keys = append(keys, entry.Name())
    42  	}
    43  	return keys, nil
    44  }
    45  

View as plain text