Skip to content

Instantly share code, notes, and snippets.

@Integralist
Last active May 30, 2025 08:35
Show Gist options
  • Save Integralist/c29ff647e5fb2f5c5001aa50a9288d8f to your computer and use it in GitHub Desktop.
Save Integralist/c29ff647e5fb2f5c5001aa50a9288d8f to your computer and use it in GitHub Desktop.
Go: remove line from file #go

We had a bug where a line [manifest_version] was being added by accident.

authors = ["[email protected]"]
description = "testing"
language = "rust"
[manifest_version]
name = "testing"
service_id = "123"
package main
import (
"bufio"
"bytes"
"log"
"os"
)
func main() {
fpath := "fastly.toml"
f, err := os.Open(fpath)
if err != nil {
log.Fatal(err)
}
defer f.Close()
var bs []byte
buf := bytes.NewBuffer(bs)
scanner := bufio.NewScanner(f)
for scanner.Scan() {
if scanner.Text() != "[manifest_version]" {
_, err := buf.Write(scanner.Bytes())
if err != nil {
log.Fatal(err)
}
_, err = buf.WriteString("\n")
if err != nil {
log.Fatal(err)
}
}
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
err = os.WriteFile(fpath, buf.Bytes(), 0666)
if err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment