simple example for config setting via .env
This commit is contained in:
		
							parent
							
								
									1f45c625e9
								
							
						
					
					
						commit
						9e73d5f69e
					
				
					 5 changed files with 18 additions and 4 deletions
				
			
		
							
								
								
									
										1
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							|  | @ -1,3 +1,4 @@ | ||||||
| bin* | bin* | ||||||
|  | .env | ||||||
| *.log | *.log | ||||||
| *.sqlite | *.sqlite | ||||||
|  |  | ||||||
|  | @ -16,6 +16,7 @@ func Config() lib.Config { | ||||||
| 		Home:    ovr(".", HOME), | 		Home:    ovr(".", HOME), | ||||||
| 		Logging: &logging.Cfg{ | 		Logging: &logging.Cfg{ | ||||||
| 			Logfile: ovr("log/scopes.log", LOGFILE), | 			Logfile: ovr("log/scopes.log", LOGFILE), | ||||||
|  | 			Level:   ovr("info", LOGLEVEL), | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -27,4 +28,5 @@ func Config() lib.Config { | ||||||
| const ( | const ( | ||||||
| 	HOME     = "home" | 	HOME     = "home" | ||||||
| 	LOGFILE  = "logfile" | 	LOGFILE  = "logfile" | ||||||
|  | 	LOGLEVEL = "loglevel" | ||||||
| ) | ) | ||||||
|  |  | ||||||
|  | @ -1,6 +1,8 @@ | ||||||
| module demo | module demo | ||||||
| 
 | 
 | ||||||
| go 1.20 | go 1.21 | ||||||
|  | 
 | ||||||
|  | toolchain go1.21.0 | ||||||
| 
 | 
 | ||||||
| require git.sr.ht/~cco/go-scopes v0.1.20 | require git.sr.ht/~cco/go-scopes v0.1.20 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										6
									
								
								examples/demo/rundemo.sh
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										6
									
								
								examples/demo/rundemo.sh
									
										
									
									
									
										Executable file
									
								
							|  | @ -0,0 +1,6 @@ | ||||||
|  | set -a | ||||||
|  | source .env | ||||||
|  | echo "log level: $SCOPES_LOGLEVEL" | ||||||
|  | 
 | ||||||
|  | bin/demo | ||||||
|  | 
 | ||||||
|  | @ -82,6 +82,9 @@ type module map[string]citem | ||||||
| 
 | 
 | ||||||
| func (m module) Compile(f forge.FE) forge.FPtr { | func (m module) Compile(f forge.FE) forge.FPtr { | ||||||
| 	v := voc.NewVoc(f.Voc()) | 	v := voc.NewVoc(f.Voc()) | ||||||
|  | 	for key, val := range m { | ||||||
|  | 		v.Register(key, val) | ||||||
|  | 	} | ||||||
| 	return f.Code(v) | 	return f.Code(v) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -102,7 +105,7 @@ type record struct { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (r *record) Compile(f forge.FE) forge.FPtr { | func (r *record) Compile(f forge.FE) forge.FPtr { | ||||||
| 	return nil | 	return f.Code(r) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (r *record) Data() interface{} { | func (r *record) Data() interface{} { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue