? How restrict usage of packages ?

152 views
Skip to first unread message

Daniel Norte Moraes

unread,
Nov 25, 2019, 11:55:55 AM11/25/19
to golang-nuts
   Hi!

   I Want create and permite my users to create go lang programs mostly with full capabilities from
golang itself, but with some direct capabilities as net and filesystem striped from direct accesss; mostly
capabilities as database access, and network access will be encapsuled in ours third parthy golang libs :-)
  The intent is use golang as a full-fledge compiled language and as substitute for a need a custom scripted language.
 
  Any sugestions and hints are wellcome! :-)


 Really Thanks in Advance! :-)
 

JuciÊ Andrade

unread,
Nov 25, 2019, 12:44:10 PM11/25/19
to golang-nuts
Add a script to your users continuous integration tool or even to their source control management.
Whenever software is compiled or commited your script will search for imports in Go source files.
If your script finds a forbidden package it should flag an error with a friendly message like this:

"You are NOT supposed to write full blown Go, but only Daniel's NearlyGo, that nowadays disallows importing package X, for your own good. In case you get angry please take out your pants and jump vigorously stepping on it again and again until you have your rage diminished somewhat. Only then, contact Daniel."


Scott Pakin

unread,
Nov 25, 2019, 7:39:30 PM11/25/19
to golang-nuts
On Monday, November 25, 2019 at 9:55:55 AM UTC-7, Daniel Norte Moraes wrote:
   I Want create and permite my users to create go lang programs mostly with full capabilities from
golang itself, but with some direct capabilities as net and filesystem striped from direct accesss; mostly
capabilities as database access, and network access will be encapsuled in ours third parthy golang libs :-)
  The intent is use golang as a full-fledge compiled language and as substitute for a need a custom scripted language.

I do something much like that for my Go Server Pages project, which lets one embed Go code in a Web page à la PHP.  The Web server administrator can choose which packages are allowed to be imported, with the default being only the provided gosp package, which encapsulates a few functions from some of the standard packages.  Check out the gosp2go source directory and in particular the ValidateImports method in utils.go.

— Scott

Daniel Norte Moraes

unread,
Dec 1, 2019, 4:46:10 AM12/1/19
to golang-nuts
Good Point!

Really Thanks! :-)

Daniel Norte Moraes

unread,
Dec 1, 2019, 4:47:46 AM12/1/19
to golang-nuts
Uau!!! Thanks a Lot! :-D

Reply all
Reply to author
Forward
0 new messages