|
1 | 1 | # update-api-1c |
2 | 2 | Client for update-api.1c.ru |
| 3 | + |
| 4 | +[![go.dev][pkg-img]][pkg] [![goreport][report-img]][report] [![build][build-img]][build] [![coverage][cov-img]][cov] ![stability-stable][stability-img] |
| 5 | + |
| 6 | + |
| 7 | +## How to use |
| 8 | + |
| 9 | +### Quick start |
| 10 | + |
| 11 | +```go |
| 12 | +package main |
| 13 | + |
| 14 | +import ( |
| 15 | + apiClient "github.com/v8platform/updateApiClient" |
| 16 | + |
| 17 | + "io" |
| 18 | + "io/ioutil" |
| 19 | + "log" |
| 20 | + "os" |
| 21 | + "path/filepath" |
| 22 | + "strings" |
| 23 | +) |
| 24 | + |
| 25 | +func main() { |
| 26 | + |
| 27 | + client := apiClient.NewClient("ITS_USER", "ITS_PASSWORD") |
| 28 | + |
| 29 | + updateInfo, err := client.GetUpdateInfo("Accounting", |
| 30 | + "3.0.88.22", |
| 31 | + apiClient.NewProgramOrRedactionUpdateType, "8.3.15.2107") |
| 32 | + |
| 33 | + if err != nil { |
| 34 | + log.Fatal(err) |
| 35 | + } |
| 36 | + |
| 37 | + updateData, err := client.GetUpdate(updateInfo.ConfigurationUpdate.ProgramVersionUin, updateInfo.ConfigurationUpdate.UpgradeSequence) |
| 38 | + |
| 39 | + if err != nil { |
| 40 | + log.Fatal(err) |
| 41 | + } |
| 42 | + |
| 43 | + for _, data := range updateData.ConfigurationUpdateDataList { |
| 44 | + |
| 45 | + updateDataFile, err := client.GetConfigurationUpdateData(data) |
| 46 | + |
| 47 | + if err != nil { |
| 48 | + log.Fatal(err) |
| 49 | + } |
| 50 | + |
| 51 | + log.Println("Download:", updateDataFile.UpdateFileUrl) |
| 52 | + |
| 53 | + distPath := strings.ReplaceAll(updateDataFile.TemplatePath, "\\", string(os.PathSeparator)) |
| 54 | + distPath = filepath.Join(".", distPath) |
| 55 | + log.Println("Path:", distPath) |
| 56 | + |
| 57 | + err = os.MkdirAll(distPath, os.ModeDir) |
| 58 | + if err != nil { |
| 59 | + log.Fatal(err) |
| 60 | + } |
| 61 | + |
| 62 | + f, err := ioutil.TempFile("", "."+updateDataFile.UpdateFileFormat) |
| 63 | + if err != nil { |
| 64 | + log.Fatal(err) |
| 65 | + } |
| 66 | + _, err = io.Copy(f, updateDataFile) |
| 67 | + |
| 68 | + f.Close() |
| 69 | + updateDataFile.Close() |
| 70 | + |
| 71 | + err = apiClient.UnzipFile(f.Name(), distPath) |
| 72 | + if err != nil { |
| 73 | + log.Fatal(err) |
| 74 | + } |
| 75 | + |
| 76 | + } |
| 77 | + |
| 78 | +} |
| 79 | + |
| 80 | +``` |
| 81 | + |
| 82 | +[pkg-img]: http://img.shields.io/badge/godoc-reference-5272B4.svg |
| 83 | +[pkg]: https://godoc.org/github.com/v8platform/updateApiClient |
| 84 | +[report-img]: https://goreportcard.com/badge/github.com/v8platform/updateApiClient |
| 85 | +[report]: https://goreportcard.com/report/github.com/v8platform/updateApiClient |
| 86 | +[build-img]: https://github.com/v8platform/updateApiClient/workflows/goreleaser/badge.svg |
| 87 | +[build]: https://github.com/v8platform/updateApiClient/actions |
| 88 | +[cov-img]: http://gocover.io/_badge/github.com/v8platform/updateApiClient |
| 89 | +[cov]: https://gocover.io/github.com/v8platform/updateApiClient |
| 90 | +[stability-img]: https://img.shields.io/badge/stability-stable-green.svg |
| 91 | + |
0 commit comments