Browse Source

use internal check function for error checking

master
Antoine 11 months ago
parent
commit
967b604bba
Signed by: antoine <antoinroux@hotmail.fr> GPG Key ID: 098FB66FC0475E70
3 changed files with 19 additions and 14 deletions
  1. +8
    -14
      cmd/wireformat/wireformat.go
  2. +2
    -0
      go.mod
  3. +9
    -0
      internal/check.go

+ 8
- 14
cmd/wireformat/wireformat.go View File

@@ -9,6 +9,8 @@ import (
"os"
"strings"

check "antoine-roux.ml/projects/go/dns-tools/internal"

"github.com/miekg/dns"
)

@@ -24,26 +26,20 @@ func main() {
var err error
if *file != "" {
if *file == "-" {
*file = "/dev/stdin"
*file = os.Stdin.Name()
}
body, err = ioutil.ReadFile(*file)
if err != nil {
log.Fatalln(err)
}
check.Check(err)

msg := &dns.Msg{}
err = msg.Unpack(body)
if err != nil {
log.Fatalln(err)
}
check.Check(err)

log.Println(msg)
} else if *domainToResolve != "" {
if *domainToResolve == "-" {
readDomainToResolve, err := ioutil.ReadFile("/dev/stdin")
if err != nil {
log.Fatalln(err)
}
readDomainToResolve, err := ioutil.ReadFile(os.Stdin.Name())
check.Check(err)
*domainToResolve = strings.TrimSuffix(string(readDomainToResolve), "\n")
}
msg := &dns.Msg{
@@ -56,9 +52,7 @@ func main() {
},
}
b, err := msg.Pack()
if err != nil {
log.Fatalln(err)
}
check.Check(err)
binary.Write(os.Stdout, binary.LittleEndian, b)
} else {
log.Println(errors.New("Too few argument pass"))


+ 2
- 0
go.mod View File

@@ -3,3 +3,5 @@ module antoine-roux.ml/projects/go/dns-tools
go 1.15

require github.com/miekg/dns v1.1.35

replace antoine-roux.ml/projects/go/dns-tools/internal => ./internal

+ 9
- 0
internal/check.go View File

@@ -0,0 +1,9 @@
package check

import "log"

func Check(err error) {
if err != nil {
log.Fatalln(err)
}
}

Loading…
Cancel
Save