-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert shell script to Go #3413
Changes from 5 commits
236ba26
4192499
59584f8
78e6ec5
e17aa7d
d48fd7e
fb19864
32865db
b410245
a3e64a8
0bb1f7b
fa74a28
8117f5e
da222d3
6b96c71
b678e7e
04794df
5ef1384
98c6e0c
5f9f4db
ec09c3d
5e7ea72
597745d
7f12569
cebc3e2
720452e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to commit the binary to the repository? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's change .gitignore. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. build/replaceRef is a piece of Bash script conversion into Go code, but our focus is on converting the whole file to Go code. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2023 Google LLC All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Package main implements a program that replaces ref with contents in the given json files | ||
package main | ||
|
||
import ( | ||
"log" | ||
markmandel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"os" | ||
"strings" | ||
) | ||
|
||
func main() { | ||
if len(os.Args) != 4 { | ||
log.Println("Usage: replaceRef <jsonFilePath> <ref> <contents>") | ||
return | ||
} | ||
|
||
jsonFilePath := os.Args[1] | ||
ref := os.Args[2] | ||
contents := os.Args[3] | ||
|
||
processJSON(jsonFilePath, ref, contents) | ||
markmandel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
func processJSON(filename, ref, contents string) { | ||
log.Println("Processing JSON file:", filename) | ||
|
||
file, err := os.ReadFile(filename) | ||
if err != nil { | ||
log.Println("Error reading:", filename, err) | ||
return | ||
} | ||
|
||
searchPattern := "\"" + ref + "\": \"#/definitions/" + ref + "\"" | ||
markmandel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
modifiedData := strings.ReplaceAll(string(file), searchPattern, contents) | ||
|
||
err = os.WriteFile(filename, []byte(modifiedData), 0o644) | ||
if err != nil { | ||
log.Println("Error writing:", filename, err) | ||
return | ||
} | ||
|
||
log.Println("JSON file processed successfully.") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know you aren't there yet, but once we have a comprehensive go script, we can delete export-openapi.sh