On Friday, November 22, 2024 at 5:27:10 PM UTC+8 Lin Lin wrote:
Hi, gophers, here is our dilemma. We build system managing infrastructure such as Kubernetes. With that comes the need to write a lot of maintenance scripts. For now they are all written in Bash, which is hard to edit and test. As the community suggests, do not write Bash code more than 100 lines. The file we wrote is more than 500 lines.Another option is to use Python, a better choice, but has its own disadvantages. When we need some capabilities beyond the standard libraries, we need to add pip rpms. The dependency is a mess and can easily corrupt the OS. That's when I started to consider Go might be an option as long as we can get rid of the compiling part. Here is the ideal Go script interpreter I wish. 1. It is a gosh like bash binary residues in the system. 2. It can invoke a script.go file, dynamically parse and execute the statements. 3. It can only support those functions and libraries compiled earlier into itself. 4. It can be easily added with any libraries in advance. 5. The source file is exactly the same with normal go source files, and can be compiled into its own separate binary. Such an interpreter can be very stable for a Bash alternative. All you need is a gosh, all other Go fmt, vet, vulcheck can seamlessly inherit. And it comes with a very little overhead for Go developers to learn and use. As far as I know, there is no such project. https://github.com/matryer/goscript is a similar one but seems out of date and depends on go toolchain; https://github.com/bitfield/script is really not a go-style one, too bash-ish. Can this be a real need? Is there any difficulties in bringing it into the real world? I'd like to hear from you gophers, thanks. There is certainly such need. But since Go 1.22, it is highly recommended not to do this. Please read: * https://go101.org/bugs/go-build-directive-not-work.html * https://go101.org/blog/2024-03-01-for-loop-semantic-changes-in-go-1.22.html Best wishes. Lin -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/7631a0c2-9606-4cde-9fe2-a76d58b3c4c1n%40googlegroups.com.