github.com/blend/go-sdk@v1.20240719.1/configutil/file.go (about)

     1  /*
     2  
     3  Copyright (c) 2024 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package configutil
     9  
    10  import (
    11  	"context"
    12  	"os"
    13  	"strings"
    14  )
    15  
    16  // File reads the string contents of a file as a literal config value.
    17  type File string
    18  
    19  // String returns the string contents of a file.
    20  func (f File) String(ctx context.Context) (*string, error) {
    21  	contents, err := os.ReadFile(string(f))
    22  	if err != nil {
    23  		return nil, nil
    24  	}
    25  	stringContents := strings.TrimSpace(string(contents))
    26  	return &stringContents, nil
    27  }