github.com/searKing/golang/go@v1.2.117/encoding/json/write.go (about)

     1  // Copyright 2022 The searKing Author. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package json
     6  
     7  import (
     8  	"encoding/json"
     9  	"os"
    10  )
    11  
    12  const permissions = 0666
    13  
    14  func WriteConfigFile(name string, v any) error {
    15  	data, err := json.MarshalIndent(v, "", "  ")
    16  	if err != nil {
    17  		return err
    18  	}
    19  	return os.WriteFile(name, data, permissions)
    20  }