go.mod और go.sum की जानकारी
In this page:
module module/path
go 1.21
require example.com/pkg v1.2.3
// go.sum: module version hash
What go.mod Contains
go.mod module का अपना import path, यह target करने वाला minimum Go version, और हर direct (और कभी-कभी indirect) dependency को exact version के साथ list करने वाला एक require block record करता है।
उदाहरण: What go.mod Contains
module github.com/example/myapp
go 1.22
require github.com/some/dependency v1.4.0
⚠️ Run this in your own terminal or Node.js environment.
What go.sum Contains
go.sum हर dependency की exact content के लिए cryptographic hashes store करता है, ताकि project बनाने वाले किसी को भी bit-for-bit एक जैसा code मिले -- किसी compromised या गलती से बदले गए package से सुरक्षा देते हुए।
उदाहरण: What go.sum Contains
github.com/some/dependency v1.4.0 h1:abcdef1234567890...
github.com/some/dependency v1.4.0/go.mod h1:1234567890abcdef...
⚠️ Run this in your own terminal or Node.js environment.
Keeping Dependencies Tidy
'go mod tidy' आपके source code की असली imports scan करता है और go.mod/go.sum को exactly उससे मेल खाने के लिए update करता है -- कुछ भी missing जोड़ते हुए और उन dependencies को हटाते हुए जो अब असल में कहीं import नहीं होतीं।
उदाहरण: Keeping Dependencies Tidy
go mod tidy
⚠️ Run this in your own terminal or Node.js environment.
Why Commit Both Files
go.mod और go.sum को version control में साथ commit करना यह गारंटी देता है कि हर developer, और हर CI build, dependencies को verified content के साथ बिल्कुल एक जैसी versions में resolve करे -- यही Go builds को reproducible बनाता है।
उदाहरण: Why Commit Both Files
// Every Go file belongs to a package; main builds an executable
package main
// Import the fmt package
import "fmt"
// main is where the program starts running
func main() {
// Print the values followed by a newline
fmt.Println("go.mod + go.sum, committed together, make builds reproducible")
}
Login to try C/C++/Java/PHP code in the editor
- go.sum को हाथ से edit करना -- यह machine-generated है और इसे सिर्फ go commands चलाकर update किया जाना चाहिए।
- यह सोचकर go.sum delete करना कि यह अनावश्यक है, जबकि यह वही है जो build को छेड़छाड़ या corrupted dependencies से बचाता है।
- go.mod commit करना लेकिन go.sum commit करना भूल जाना, दूसरे developers के लिए reproducible builds तोड़ते हुए।
- go.mod module की identity, Go version, और इसकी required dependencies को versions के साथ declare करता है।
- go.sum हर dependency की अखंडता verify करते हुए cryptographic checksums record करता है।
- दोनों files को हमेशा version control में साथ commit करना चाहिए।
- 'go mod tidy' go.mod और go.sum को accurate रखता है, missing जोड़ते हुए और unused requirements हटाते हुए।
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: