Skip to content

Commit

Permalink
Merge pull request #78 from nextmn/gofmt
Browse files Browse the repository at this point in the history
Gofmt
  • Loading branch information
louisroyer authored Sep 17, 2024
2 parents 1fb3b60 + 7c46708 commit 79115ee
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 29 deletions.
2 changes: 1 addition & 1 deletion internal/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (db *Database) Init(ctx context.Context) error {
for i := range v.num_in {
args = append(args, fmt.Sprintf("$%d", i+1))
}
for _ = range v.num_out {
for range v.num_out {
args = append(args, "NULL")
}
strargs := strings.Join(args, ", ")
Expand Down
24 changes: 12 additions & 12 deletions internal/database/database_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 26 additions & 13 deletions internal/database/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ package main

import (
"bufio"
"bytes"
"fmt"
"go/format"
"io"
"os"
"strings"
)
Expand Down Expand Up @@ -39,13 +42,8 @@ func main() {
}
output = strings.Replace(output, ".go", "_gen.go", 1)

f, err := os.Create(output)
if err != nil {
panic(err)
}
defer f.Close()

if _, err = f.WriteString("// Code generated by gen.go; DO NOT EDIT.\n"); err != nil {
var f bytes.Buffer
if _, err := f.WriteString("// Code generated by gen.go; DO NOT EDIT.\n"); err != nil {
panic(err)
}
licence := `
Expand All @@ -54,16 +52,16 @@ func main() {
// found in the LICENSE file.
`
if _, err = f.WriteString(licence); err != nil {
if _, err := f.WriteString(licence); err != nil {
panic(err)
}
if _, err = f.WriteString("package database\n\n"); err != nil {
if _, err := f.WriteString("package database\n\n"); err != nil {
panic(err)
}
if _, err = f.WriteString("type procedureOrFunction struct {\n\tnum_in int\n\tnum_out int\n\tis_procedure bool\n}\n\n"); err != nil {
if _, err := f.WriteString("type procedureOrFunction struct {\n\tnum_in int\n\tnum_out int\n\tis_procedure bool\n}\n\n"); err != nil {
panic(err)
}
if _, err = f.WriteString("var procedures = map[string]procedureOrFunction{\n"); err != nil {
if _, err := f.WriteString("var procedures = map[string]procedureOrFunction{\n"); err != nil {
panic(err)
}
fr, err := os.OpenFile(input, os.O_RDONLY, 0)
Expand Down Expand Up @@ -92,7 +90,7 @@ func main() {
}
psplit := strings.Split(psuffix, "(")
pname := psplit[0]
if _, err = f.WriteString(fmt.Sprintf("\t\"%s\": procedureOrFunction{is_procedure: true, ", pname)); err != nil {
if _, err = f.WriteString(fmt.Sprintf("\t\"%s\": {is_procedure: true, ", pname)); err != nil {
panic(err)
}
stateParser = StateCheckNbArgs
Expand All @@ -105,7 +103,7 @@ func main() {
}
psplit := strings.Split(fsuffix, "(")
pname := psplit[0]
if _, err = f.WriteString(fmt.Sprintf("\t\"%s\": procedureOrFunction{is_procedure: false, ", pname)); err != nil {
if _, err = f.WriteString(fmt.Sprintf("\t\"%s\": {is_procedure: false, ", pname)); err != nil {
panic(err)
}
stateParser = StateCheckNbArgs
Expand All @@ -129,4 +127,19 @@ func main() {
if _, err = f.WriteString("}\n"); err != nil {
panic(err)
}

// running go fmt
formatted, err := format.Source(f.Bytes())
if err != nil {
panic(err)
}

fout, err := os.Create(output)
if err != nil {
panic(err)
}
defer fout.Close()
if _, err = io.Copy(fout, bytes.NewReader(formatted)); err != nil {
panic(err)
}
}
2 changes: 1 addition & 1 deletion internal/netfunc/endpoint-m-gtp4-e.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (e EndpointMGTP4E) Handle(ctx context.Context, packet []byte) ([]byte, erro
// message type: G-PDU
MessageType: constants.GTPU_MESSAGE_TYPE_GPDU,
TEID: ipv6DA.PDUSessionID(),
// Unfortunatelly, gopacket is not able to compute length at serialization for GTP…
// Unfortunately, gopacket is not able to compute length at serialization for GTP…
// We need to do it manually :(
// TS 128281:
// > This field indicates the length in octets of the payload, i.e. the rest of the packet following the mandatory
Expand Down
4 changes: 2 additions & 2 deletions internal/netfunc/headend-gtp4.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (h HeadendGTP4) Handle(ctx context.Context, packet []byte) ([]byte, error)

var bsid *config.Bsid

// find a policy matching criterias
// find a policy matching criteria
for _, p := range h.policy {
// catch-all policy (should be last policy in list)
if p.Match == nil {
Expand Down Expand Up @@ -131,7 +131,7 @@ func (h HeadendGTP4) Handle(ctx context.Context, packet []byte) ([]byte, error)
}
}
if bsid == nil {
return nil, fmt.Errorf("Could not found policy matching criterias")
return nil, fmt.Errorf("Could not found policy matching criteria")
}

if bsid.BsidPrefix == nil {
Expand Down

0 comments on commit 79115ee

Please sign in to comment.