update
This commit is contained in:
parent
50e482fbd4
commit
22c6b76104
2
go.mod
2
go.mod
@ -1,3 +1,5 @@
|
||||
module git.macaw.me/inhosin/vvod
|
||||
|
||||
go 1.14
|
||||
|
||||
require github.com/BurntSushi/toml v0.3.1
|
||||
|
2
go.sum
Normal file
2
go.sum
Normal file
@ -0,0 +1,2 @@
|
||||
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
38
main.go
38
main.go
@ -5,25 +5,25 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
)
|
||||
|
||||
var (
|
||||
// TOKEN token
|
||||
TOKEN = "08bb51ff-1eb6-4167-8ed2-eb19fc343703"
|
||||
// MICROSERVICEURL url to microservie
|
||||
MICROSERVICEURL = "http://microservice01:8081/api/v1/documents/create?crptDocType=LP_INTRODUCE_OST"
|
||||
config Setting
|
||||
configPath string
|
||||
filePath string
|
||||
)
|
||||
|
||||
// Hello ...
|
||||
func Hello(name string) string {
|
||||
if name == "" {
|
||||
name = "World"
|
||||
}
|
||||
return fmt.Sprintf("Hello, %s", name)
|
||||
func init() {
|
||||
flag.StringVar(&configPath, "config-path", "./settings/settings.toml", "Path to config file")
|
||||
flag.StringVar(&filePath, "file", "test.csv", "Path to file with some cis")
|
||||
}
|
||||
|
||||
// ParseFile ...
|
||||
@ -94,22 +94,23 @@ func SendToMicroservice(fileName string) error {
|
||||
products = append(products, cis)
|
||||
}
|
||||
}
|
||||
document := NewDocument("122323", products)
|
||||
document := NewDocument(fileName, products)
|
||||
|
||||
data, err := json.Marshal(document)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("POST", MICROSERVICEURL, bytes.NewBuffer(data))
|
||||
req, err := http.NewRequest("POST", config.MicroServiceURL, bytes.NewBuffer(data))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("token", TOKEN)
|
||||
req.Header.Set("token", config.Token)
|
||||
|
||||
client := http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
fmt.Printf("Make request to %s\n with data %s\n", config.MicroServiceURL, string(data))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -130,7 +131,7 @@ func MakePartFile(lines []string, fName string) error {
|
||||
defer file.Close()
|
||||
|
||||
for _, line := range lines {
|
||||
if _, err := file.WriteString(fmt.Sprintln(line)); err != nil {
|
||||
if _, err := file.WriteString(fmt.Sprintln(line[0:31])); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -139,9 +140,14 @@ func MakePartFile(lines []string, fName string) error {
|
||||
}
|
||||
|
||||
func main() {
|
||||
Hello("")
|
||||
flag.Parse()
|
||||
|
||||
lines, err := ParseFile("codes.csv")
|
||||
_, err := toml.DecodeFile(configPath, &config)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
lines, err := ParseFile(filePath)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
|
@ -23,5 +23,6 @@ func NewDocument(docNum string, products []Cis) *Document {
|
||||
|
||||
// NewCis ...
|
||||
func NewCis(cis string) Cis {
|
||||
return Cis{Ki: cis}
|
||||
shortCIS := cis[0:31]
|
||||
return Cis{Ki: shortCIS}
|
||||
}
|
||||
|
7
settings.go
Normal file
7
settings.go
Normal file
@ -0,0 +1,7 @@
|
||||
package main
|
||||
|
||||
// Setting struct for config
|
||||
type Setting struct {
|
||||
Token string `toml:"TOKEN"`
|
||||
MicroServiceURL string `toml:"MICROSERVICEURL"`
|
||||
}
|
2
settings/settings.toml
Normal file
2
settings/settings.toml
Normal file
@ -0,0 +1,2 @@
|
||||
TOKEN = "08bb51ff-1eb6-4167-8ed2-eb19fc343703"
|
||||
MICROSERVICEURL = "http://microservice01:8081/api/v1/documents/create?crptDocType=LP_INTRODUCE_OST"
|
Loading…
Reference in New Issue
Block a user