Skip to content

ShindouMihou/go-bun

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

go-bun

Warning!

go-bun is intended to be a little fun joke. do not ever use it in production. a proper version of the files interface that sports a similar feel to bun's with a golang touch, feature-packed is available at siopao.

some little fun experimentation and remake of random stuff from other languages. initially, this was to remake the cool
interfaces that bun.sh had for files, but then expanded to figuring out how to remake stuff from other languages.

what does go-bun have:

  • promises: literally javascript promises, but dumbed down and made into a linked-list structure.
  • try-catch: literally java and javscript try-catch, but dumbed down.
  • files: literally bun.sh's files interface, dumbed for golang.

error-handling.

in order to imitate the simple look of bun.sh's interfaces, we also need to let go of golang's error-handling, and that's where go-bun's try-catch system comes into play.

func main() {
	bun.Try(func() {
		file := bun.File("examples/test-overwrite")
		file.Overwrite("hello")
	}).Catch(func(err any) {
		fmt.Println("failed to perform write operations: ", err)
	}).Run()
}

literally... try-catch!

promises

we can't anything javascript without promises, right? hell yes, we have promises and it's built with craziness, it's like traditional promises, but crazy:

func main() {
	bun.NewPromise(func(res any) any {
		file := bun.File("test")
		return file.Text()
	}).Exceptionally(func(res any) any {
		fmt.Println("failed to read file", res)
		return nil
	}).Then(func(res any) any {
		return strings.ReplaceAll(res.(string), "s", "r")
	}).Then(func(res any) any {
		fmt.Println(res)
		return nil
	}).Await()
}

About

bringing random js things to go.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages