1234567891011121314151617181920 |
- // Copyright 2025 BackendServerTemplate Authors. All rights reserved.
- // Use of this source code is governed by a MIT-style
- // license that can be found in the LICENSE file.
- package fileutils
- import "os"
- func Write(filePath string, dat string) error {
- // 尝试打开文件
- file, err := os.OpenFile(filePath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
- if err != nil {
- return err
- }
- defer func() {
- _ = file.Close()
- }()
- _, err = file.Write([]byte(dat))
- return err
- }
|