• Stars
    star
    161
  • Rank 233,470 (Top 5 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created over 10 years ago
  • Updated over 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Go Script Language

gosl GoSearch

This is an application that can make you write script with the Go language.

It is NOT an interpreter but the pure Go. The preprocessor tranforms the script into a Go program, instantly compiles and runs. So it is almost same as the standard Go with the same efficiency.

Benefit

  1. Pure Go language. No need to learn a new script language.
  2. Pre-imported packages and pre-defined functions make it easy to code.
  3. Seamless integration with the Go project. E.g. can easily load configuration or data file from the Go project.
  4. Running efficiency same as Go, much faster than Python.

Example

  • Simple
#!/bin/gosl

import "encoding/json"

toJson := func(lines []string) string {
  res, _ := json.Marshal(struct {
    Lines []string `json:"lines"`
  }{
    Lines: lines,
  })
  return string(res)
}

files := BashEval("ls -l %s", "/tmp/")

Println(toJson(Split(files, "\n")))
    

Installation and Usage

Download and install the package

go get github.com/daviddengcn/gosl
go install github.com/daviddengcn/gosl

(Optional) Link to /bin

sudo ln -s $GOPATH/bin/gosl /bin/gosl

If you don't want to do this, the interpreter line can be like this, assuming $GOPATH/bin is in your $PATH:

#!/usr/bin/env gosl

Run a script

If a script starts with the bash interpreter line: #!/bin/gosl. You can run it like this

chmod a+x example.gs
./example.gs [params...]

Or you can explictly call gosl to run it:

gosl example.gs [params...]

Pre-imported Packages

The following packages are pre-imported with ., i.e. you can directly use the methods exported by them. No complain of the compiler if you don't use them.

fmt, os, strings, strconv, math, time, and github.com/daviddengcn/gosl/builtin

Frequently Used builtin Functions

Method Description Example
S Convert anything to a string S(1234) == "123"
I Convert anything to an int I("1234") == 1234
BashEval Similar to bash backtick substitution. lsstr := BashEval("ls -l")
Exec Execute an command with arguments err, code := Exec("rm", "-rf" "tmp")
Bash Execute a bash line err, code := Bash("rm -rf tmp")
ScriptDir Returns the directory of the script file := ScriptDir() + "/" + fn

More functions are defined in package daviddengcn/gosl/builtin/ (godoc)

License

Apache License V2

More Repositories

1

gcse

Project for Go Search, a search engine for finding popular and relevant packages.
Go
277
star
2

go-colortext

Change the color of console text.
Go
214
star
3

go-diff

A diff tool especially for Go language.
Go
71
star
4

go-pr

Pattern recognition package in Go lang.
Go
62
star
5

go-villa

Some helper types for go1: priority queue, slice wrapper.
Go
52
star
6

patch-ext

Git Patch Rendering Chrome Extension
JavaScript
34
star
7

go-index

Text indexing related functions in Go, including tokenizer, word marking, and snippet selecting, etc.
Go
27
star
8

go-algs

Some algorithms in go: maxflow(min-cuts or graph-cuts), edit-distance.
Go
16
star
9

go-rpc

Go RPC framework
Go
9
star
10

ljson

Loose JSON, a superset of JSON with a loose format requirement.
Go
8
star
11

go-vision

Computer vision related functions in Go.
Go
6
star
12

go-ljson-conf

A powerful configuration package for go using Loose JSON as the format
Go
5
star
13

geps

JavaScript
4
star
14

go-prolog

Go programming as a Prolog style
Go
4
star
15

menu

A tool for showing menu under linux command line.
Go
3
star
16

lockfreepool

A Java Lock Free Pool
Java
3
star
17

sgrep

Structural grep
Go
3
star
18

go-html-frame

HTML framework for Go web.
Go
3
star
19

sea

A branch from http://seashore.sourceforge.net/
Objective-C
2
star
20

insert-css-rules-ext

Chrome extension to insert css rules automatically.
JavaScript
2
star
21

go-assert

Testing utils for Go.
Go
2
star
22

sophie

A sequencial data processing library.
Go
2
star
23

go-shell

A shell environment interpreting and running Go code.
Go
2
star
24

go-code-crawl

Crawler for go-code engine.
Go
2
star
25

gdr

go-debug-run tool
Go
1
star
26

ynote-import

Youdao note importer
Go
1
star
27

japanese-learning

Some useful stuffs related to Japanese learning.
1
star
28

bolthelper

Helper classes for bolt.
Go
1
star
29

cpp-freevision

The free-vision project aims at creating a library for computer vision related functions, including camera capture interface, stereo, image processing, camera calibration and so on.
C++
1
star