added error signalling to NewMacroInjectTarget

This commit is contained in:
dtookey 2022-08-09 11:48:51 -04:00
parent 95f8ec4c1c
commit a1708563be
3 changed files with 7 additions and 8 deletions

View File

@ -1,4 +0,0 @@
package main
func main() {
}

2
go.mod
View File

@ -1,3 +1,3 @@
module Wordifier
module geniuscartel.xyz/wordifier
go 1.18

View File

@ -3,6 +3,8 @@ package word
import (
zip2 "archive/zip"
"bytes"
"errors"
"fmt"
"io"
"io/ioutil"
"os"
@ -16,11 +18,12 @@ type (
}
)
func NewMacroInjectTarget(name string, marker []byte, replacement []byte) MacroInjectTarget {
func NewMacroInjectTarget(name string, marker []byte, replacement []byte) (*MacroInjectTarget, error) {
if len(replacement) != len(marker) {
panic("Payload and target are not the same size. Make sure replacement is the same length as marker")
err := errors.New(fmt.Sprintf("Payload[%d] and target[%d] are not the same size. Make sure replacement is the same length as marker", len(replacement), len(marker)))
return nil, err
}
return MacroInjectTarget{name, marker, replacement}
return &MacroInjectTarget{name, marker, replacement}, nil
}
func CopyZipWithReplacements(src string, dest io.Writer, replacements []MacroInjectTarget) {