Merge branch 'development_kristof10' into development
# Conflicts: # .github/workflows/build_and_test.yml # .github/workflows/hero_build_linux.yml # .github/workflows/hero_build_macos.yml # install_herolib.vsh # install_v.sh # workflows/hero_build_macos.yml
This commit is contained in:
@@ -34,7 +34,7 @@ The examples directory demonstrates various capabilities of HeroLib:
|
||||
When creating V scripts (.vsh files), always use the following shebang:
|
||||
|
||||
```bash
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
```
|
||||
|
||||
This shebang ensures:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.builder
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.builder
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.builder
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
|
||||
24
examples/clients/mail.vsh
Executable file
24
examples/clients/mail.vsh
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
|
||||
import freeflowuniverse.herolib.clients. mailclient
|
||||
|
||||
|
||||
//remove the previous one, otherwise the env variables are not read
|
||||
mailclient.config_delete(name:"test")!
|
||||
|
||||
// env variables which need to be set are:
|
||||
// - MAIL_FROM=...
|
||||
// - MAIL_PASSWORD=...
|
||||
// - MAIL_PORT=465
|
||||
// - MAIL_SERVER=...
|
||||
// - MAIL_USERNAME=...
|
||||
|
||||
|
||||
mut client:= mailclient.get(name:"test")!
|
||||
|
||||
println(client)
|
||||
|
||||
client.send(subject:'this is a test',to:'kristof@incubaid.com',body:'
|
||||
this is my email content
|
||||
')!
|
||||
45
examples/clients/psql.vsh
Executable file
45
examples/clients/psql.vsh
Executable file
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.core
|
||||
import freeflowuniverse.herolib.clients.postgresql_client
|
||||
|
||||
|
||||
// Configure PostgreSQL client
|
||||
heroscript := "
|
||||
!!postgresql_client.configure
|
||||
name:'test'
|
||||
user: 'postgres'
|
||||
port: 5432
|
||||
host: 'localhost'
|
||||
password: '1234'
|
||||
dbname: 'postgres'
|
||||
"
|
||||
|
||||
// Process the heroscript configuration
|
||||
postgresql_client.play(heroscript: heroscript)!
|
||||
|
||||
// Get the configured client
|
||||
mut db_client := postgresql_client.get(name: "test")!
|
||||
|
||||
// Check if test database exists, create if not
|
||||
if !db_client.db_exists('test')! {
|
||||
println('Creating database test...')
|
||||
db_client.db_create('test')!
|
||||
}
|
||||
|
||||
// Switch to test database
|
||||
db_client.dbname = 'test'
|
||||
|
||||
// Create table if not exists
|
||||
create_table_sql := "CREATE TABLE IF NOT EXISTS users (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name VARCHAR(100) NOT NULL,
|
||||
email VARCHAR(255) UNIQUE NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)"
|
||||
|
||||
println('Creating table users if not exists...')
|
||||
db_client.exec(create_table_sql)!
|
||||
|
||||
println('Database and table setup completed successfully!')
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.core.base
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
import freeflowuniverse.herolib.core.base
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.develop.gittools
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import os
|
||||
import freeflowuniverse.herolib.core.codeparser
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import time
|
||||
import freeflowuniverse.herolib.core.smartid
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.data.dbfs
|
||||
import time
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.core.generator.installer
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import os
|
||||
import json
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
import os
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
import os
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
import freeflowuniverse.herolib.data.paramsparser
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
import os
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.crypt.secrets
|
||||
|
||||
|
||||
1
examples/data/.gitignore
vendored
Normal file
1
examples/data/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
cache
|
||||
139
examples/data/cache.vsh
Executable file
139
examples/data/cache.vsh
Executable file
@@ -0,0 +1,139 @@
|
||||
#!/usr/bin/env -S v run
|
||||
|
||||
// Example struct to cache
|
||||
import freeflowuniverse.herolib.data.cache
|
||||
import time
|
||||
|
||||
@[heap]
|
||||
struct User {
|
||||
id u32
|
||||
name string
|
||||
age int
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Create a cache with custom configuration
|
||||
config := cache.CacheConfig{
|
||||
max_entries: 1000 // Maximum number of entries
|
||||
max_size_mb: 10.0 // Maximum cache size in MB
|
||||
ttl_seconds: 300 // Items expire after 5 minutes
|
||||
eviction_ratio: 0.2 // Evict 20% of entries when full
|
||||
}
|
||||
|
||||
mut user_cache := cache.new_cache[User](config)
|
||||
|
||||
// Create some example users
|
||||
user1 := &User{
|
||||
id: 1
|
||||
name: 'Alice'
|
||||
age: 30
|
||||
}
|
||||
|
||||
user2 := &User{
|
||||
id: 2
|
||||
name: 'Bob'
|
||||
age: 25
|
||||
}
|
||||
|
||||
// Add users to cache
|
||||
println('Adding users to cache...')
|
||||
user_cache.set(user1.id, user1)
|
||||
user_cache.set(user2.id, user2)
|
||||
|
||||
// Retrieve users from cache
|
||||
println('\nRetrieving users from cache:')
|
||||
if cached_user1 := user_cache.get(1) {
|
||||
println('Found user 1: ${cached_user1.name}, age ${cached_user1.age}')
|
||||
}
|
||||
|
||||
if cached_user2 := user_cache.get(2) {
|
||||
println('Found user 2: ${cached_user2.name}, age ${cached_user2.age}')
|
||||
}
|
||||
|
||||
// Try to get non-existent user
|
||||
println('\nTrying to get non-existent user:')
|
||||
if user := user_cache.get(999) {
|
||||
println('Found user: ${user.name}')
|
||||
} else {
|
||||
println('User not found in cache')
|
||||
}
|
||||
|
||||
// Demonstrate cache stats
|
||||
println('\nCache statistics:')
|
||||
println('Number of entries: ${user_cache.len()}')
|
||||
|
||||
// Clear the cache
|
||||
println('\nClearing cache...')
|
||||
user_cache.clear()
|
||||
println('Cache entries after clear: ${user_cache.len()}')
|
||||
|
||||
// Demonstrate max entries limit
|
||||
println('\nDemonstrating max entries limit (adding 2000 entries):')
|
||||
println('Initial cache size: ${user_cache.len()}')
|
||||
|
||||
for i := u32(0); i < 2000; i++ {
|
||||
user := &User{
|
||||
id: i
|
||||
name: 'User${i}'
|
||||
age: 20 + int(i % 50)
|
||||
}
|
||||
user_cache.set(i, user)
|
||||
|
||||
if i % 200 == 0 {
|
||||
println('After adding ${i} entries:')
|
||||
println(' Cache size: ${user_cache.len()}')
|
||||
|
||||
// Check some entries to verify LRU behavior
|
||||
if i >= 500 {
|
||||
old_id := if i < 1000 { u32(0) } else { i - 1000 }
|
||||
recent_id := i - 1
|
||||
println(' Entry ${old_id} (old): ${if _ := user_cache.get(old_id) {
|
||||
'found'
|
||||
} else {
|
||||
'evicted'
|
||||
}}')
|
||||
println(' Entry ${recent_id} (recent): ${if _ := user_cache.get(recent_id) {
|
||||
'found'
|
||||
} else {
|
||||
'evicted'
|
||||
}}')
|
||||
}
|
||||
println('')
|
||||
}
|
||||
}
|
||||
|
||||
println('Final statistics:')
|
||||
println('Cache size: ${user_cache.len()} (should be max 1000)')
|
||||
|
||||
// Verify we can only access recent entries
|
||||
println('\nVerifying LRU behavior:')
|
||||
println('First entry (0): ${if _ := user_cache.get(0) { 'found' } else { 'evicted' }}')
|
||||
println('Middle entry (1000): ${if _ := user_cache.get(1000) { 'found' } else { 'evicted' }}')
|
||||
println('Recent entry (1900): ${if _ := user_cache.get(1900) { 'found' } else { 'evicted' }}')
|
||||
println('Last entry (1999): ${if _ := user_cache.get(1999) { 'found' } else { 'evicted' }}')
|
||||
|
||||
// Demonstrate TTL expiration
|
||||
println('\nDemonstrating TTL expiration:')
|
||||
quick_config := cache.CacheConfig{
|
||||
ttl_seconds: 2 // Set short TTL for demo
|
||||
}
|
||||
mut quick_cache := cache.new_cache[User](quick_config)
|
||||
|
||||
// Add a user
|
||||
quick_cache.set(user1.id, user1)
|
||||
println('Added user to cache with 2 second TTL')
|
||||
|
||||
if cached := quick_cache.get(user1.id) {
|
||||
println('User found immediately: ${cached.name}')
|
||||
}
|
||||
|
||||
// Wait for TTL to expire
|
||||
println('Waiting for TTL to expire...')
|
||||
time.sleep(3 * time.second)
|
||||
|
||||
if _ := quick_cache.get(user1.id) {
|
||||
println('User still in cache')
|
||||
} else {
|
||||
println('User expired from cache as expected')
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.data.encoder
|
||||
import crypto.ed25519
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.crypt.aes_symmetric { decrypt, encrypt }
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
175
examples/data/graphdb.vsh
Executable file
175
examples/data/graphdb.vsh
Executable file
@@ -0,0 +1,175 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
// Example demonstrating GraphDB usage in a social network context
|
||||
import freeflowuniverse.herolib.data.graphdb
|
||||
|
||||
fn main() {
|
||||
// Initialize a new graph database with default cache settings
|
||||
mut gdb := graphdb.new(
|
||||
path: '/tmp/social_network_example'
|
||||
reset: true // Start fresh each time
|
||||
)!
|
||||
|
||||
println('=== Social Network Graph Example ===\n')
|
||||
|
||||
// 1. Creating User Nodes
|
||||
println('Creating users...')
|
||||
mut alice_id := gdb.create_node({
|
||||
'type': 'user'
|
||||
'name': 'Alice Chen'
|
||||
'age': '28'
|
||||
'location': 'San Francisco'
|
||||
'occupation': 'Software Engineer'
|
||||
})!
|
||||
println('Created user: ${gdb.debug_node(alice_id)!}')
|
||||
|
||||
mut bob_id := gdb.create_node({
|
||||
'type': 'user'
|
||||
'name': 'Bob Smith'
|
||||
'age': '32'
|
||||
'location': 'New York'
|
||||
'occupation': 'Product Manager'
|
||||
})!
|
||||
println('Created user: ${gdb.debug_node(bob_id)!}')
|
||||
|
||||
mut carol_id := gdb.create_node({
|
||||
'type': 'user'
|
||||
'name': 'Carol Davis'
|
||||
'age': '27'
|
||||
'location': 'San Francisco'
|
||||
'occupation': 'Data Scientist'
|
||||
})!
|
||||
println('Created user: ${gdb.debug_node(carol_id)!}')
|
||||
|
||||
// 2. Creating Organization Nodes
|
||||
println('\nCreating organizations...')
|
||||
mut techcorp_id := gdb.create_node({
|
||||
'type': 'organization'
|
||||
'name': 'TechCorp'
|
||||
'industry': 'Technology'
|
||||
'location': 'San Francisco'
|
||||
'size': '500+'
|
||||
})!
|
||||
println('Created organization: ${gdb.debug_node(techcorp_id)!}')
|
||||
|
||||
mut datacorp_id := gdb.create_node({
|
||||
'type': 'organization'
|
||||
'name': 'DataCorp'
|
||||
'industry': 'Data Analytics'
|
||||
'location': 'New York'
|
||||
'size': '100-500'
|
||||
})!
|
||||
println('Created organization: ${gdb.debug_node(datacorp_id)!}')
|
||||
|
||||
// 3. Creating Interest Nodes
|
||||
println('\nCreating interest groups...')
|
||||
mut ai_group_id := gdb.create_node({
|
||||
'type': 'group'
|
||||
'name': 'AI Enthusiasts'
|
||||
'category': 'Technology'
|
||||
'members': '0'
|
||||
})!
|
||||
println('Created group: ${gdb.debug_node(ai_group_id)!}')
|
||||
|
||||
// 4. Establishing Relationships
|
||||
println('\nCreating relationships...')
|
||||
|
||||
// Friendship relationships
|
||||
gdb.create_edge(alice_id, bob_id, 'FRIENDS', {
|
||||
'since': '2022'
|
||||
'strength': 'close'
|
||||
})!
|
||||
gdb.create_edge(alice_id, carol_id, 'FRIENDS', {
|
||||
'since': '2023'
|
||||
'strength': 'close'
|
||||
})!
|
||||
|
||||
// Employment relationships
|
||||
gdb.create_edge(alice_id, techcorp_id, 'WORKS_AT', {
|
||||
'role': 'Senior Engineer'
|
||||
'since': '2021'
|
||||
'department': 'Engineering'
|
||||
})!
|
||||
gdb.create_edge(bob_id, datacorp_id, 'WORKS_AT', {
|
||||
'role': 'Product Lead'
|
||||
'since': '2020'
|
||||
'department': 'Product'
|
||||
})!
|
||||
gdb.create_edge(carol_id, techcorp_id, 'WORKS_AT', {
|
||||
'role': 'Data Scientist'
|
||||
'since': '2022'
|
||||
'department': 'Analytics'
|
||||
})!
|
||||
|
||||
// Group memberships
|
||||
gdb.create_edge(alice_id, ai_group_id, 'MEMBER_OF', {
|
||||
'joined': '2023'
|
||||
'status': 'active'
|
||||
})!
|
||||
gdb.create_edge(carol_id, ai_group_id, 'MEMBER_OF', {
|
||||
'joined': '2023'
|
||||
'status': 'active'
|
||||
})!
|
||||
|
||||
// 5. Querying the Graph
|
||||
println('\nPerforming queries...')
|
||||
|
||||
// Find users in San Francisco
|
||||
println('\nUsers in San Francisco:')
|
||||
sf_users := gdb.query_nodes_by_property('location', 'San Francisco')!
|
||||
for user in sf_users {
|
||||
if user.properties['type'] == 'user' {
|
||||
println('- ${user.properties['name']} (${user.properties['occupation']})')
|
||||
}
|
||||
}
|
||||
|
||||
// Find Alice's friends
|
||||
println("\nAlice's friends:")
|
||||
alice_friends := gdb.get_connected_nodes(alice_id, 'FRIENDS', 'out')!
|
||||
for friend in alice_friends {
|
||||
println('- ${friend.properties['name']} in ${friend.properties['location']}')
|
||||
}
|
||||
|
||||
// Find where Alice works
|
||||
println("\nAlice's workplace:")
|
||||
alice_workplaces := gdb.get_connected_nodes(alice_id, 'WORKS_AT', 'out')!
|
||||
for workplace in alice_workplaces {
|
||||
println('- ${workplace.properties['name']} (${workplace.properties['industry']})')
|
||||
}
|
||||
|
||||
// Find TechCorp employees
|
||||
println('\nTechCorp employees:')
|
||||
techcorp_employees := gdb.get_connected_nodes(techcorp_id, 'WORKS_AT', 'in')!
|
||||
for employee in techcorp_employees {
|
||||
println('- ${employee.properties['name']} as ${employee.properties['occupation']}')
|
||||
}
|
||||
|
||||
// Find AI group members
|
||||
println('\nAI Enthusiasts group members:')
|
||||
ai_members := gdb.get_connected_nodes(ai_group_id, 'MEMBER_OF', 'in')!
|
||||
for member in ai_members {
|
||||
println('- ${member.properties['name']}')
|
||||
}
|
||||
|
||||
// 6. Updating Data
|
||||
println('\nUpdating data...')
|
||||
|
||||
// Promote Alice
|
||||
println('\nPromoting Alice...')
|
||||
mut alice := gdb.get_node(alice_id)!
|
||||
alice.properties['occupation'] = 'Lead Software Engineer'
|
||||
gdb.update_node(alice_id, alice.properties)!
|
||||
|
||||
// Update Alice's work relationship
|
||||
mut edges := gdb.get_edges_between(alice_id, techcorp_id)!
|
||||
if edges.len > 0 {
|
||||
gdb.update_edge(edges[0].id, {
|
||||
'role': 'Engineering Team Lead'
|
||||
'since': '2021'
|
||||
'department': 'Engineering'
|
||||
})!
|
||||
}
|
||||
|
||||
println('\nFinal graph structure:')
|
||||
gdb.print_graph()!
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.data.encoderhero
|
||||
import freeflowuniverse.herolib.core.base
|
||||
|
||||
30
examples/data/heroencoder_simple.vsh
Executable file
30
examples/data/heroencoder_simple.vsh
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.data.encoderhero
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import time
|
||||
|
||||
struct Person {
|
||||
mut:
|
||||
name string
|
||||
age int = 20
|
||||
birthday time.Time
|
||||
}
|
||||
|
||||
mut person := Person{
|
||||
name: 'Bob'
|
||||
birthday: time.now()
|
||||
}
|
||||
heroscript := encoderhero.encode[Person](person)!
|
||||
|
||||
println(heroscript)
|
||||
|
||||
person2 := encoderhero.decode[Person](heroscript)!
|
||||
println(person2)
|
||||
|
||||
//show that it doesn't matter which action & method is used
|
||||
heroscript2:="!!a.b name:Bob age:20 birthday:'2025-02-06 09:57:30'"
|
||||
person3 := encoderhero.decode[Person](heroscript)!
|
||||
|
||||
println(person3)
|
||||
|
||||
37
examples/data/jsonexample.vsh
Executable file
37
examples/data/jsonexample.vsh
Executable file
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
|
||||
import json
|
||||
|
||||
enum JobTitle {
|
||||
manager
|
||||
executive
|
||||
worker
|
||||
}
|
||||
|
||||
struct Employee {
|
||||
mut:
|
||||
name string
|
||||
family string @[json: '-'] // this field will be skipped
|
||||
age int
|
||||
salary f32
|
||||
title JobTitle @[json: 'ETitle'] // the key for this field will be 'ETitle', not 'title'
|
||||
notes string @[omitempty] // the JSON property is not created if the string is equal to '' (an empty string).
|
||||
// TODO: document @[raw]
|
||||
}
|
||||
|
||||
x := Employee{'Peter', 'Begins', 28, 95000.5, .worker, ''}
|
||||
println(x)
|
||||
s := json.encode(x)
|
||||
println('JSON encoding of employee x: ${s}')
|
||||
assert s == '{"name":"Peter","age":28,"salary":95000.5,"ETitle":"worker"}'
|
||||
mut y := json.decode(Employee, s)!
|
||||
assert y != x
|
||||
assert y.family == ''
|
||||
y.family = 'Begins'
|
||||
assert y == x
|
||||
println(y)
|
||||
ss := json.encode(y)
|
||||
println('JSON encoding of employee y: ${ss}')
|
||||
assert ss == s
|
||||
|
||||
64
examples/data/location/location_example.vsh
Executable file
64
examples/data/location/location_example.vsh
Executable file
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env -S v -n -w -cg -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.clients.postgresql_client
|
||||
import freeflowuniverse.herolib.data.location
|
||||
|
||||
// Configure PostgreSQL client
|
||||
heroscript := "
|
||||
!!postgresql_client.configure
|
||||
name:'test'
|
||||
user: 'postgres'
|
||||
port: 5432
|
||||
host: 'localhost'
|
||||
password: '1234'
|
||||
dbname: 'postgres'
|
||||
"
|
||||
|
||||
// Process the heroscript configuration
|
||||
postgresql_client.play(heroscript: heroscript)!
|
||||
|
||||
// Get the configured client
|
||||
mut db_client := postgresql_client.get(name: "test")!
|
||||
|
||||
|
||||
// Create a new location instance
|
||||
mut loc := location.new(mut db_client, false) or { panic(err) }
|
||||
println('Location database initialized')
|
||||
|
||||
// Initialize the database (downloads and imports data)
|
||||
// This only needs to be done once or when updating data
|
||||
println('Downloading and importing location data (this may take a few minutes)...')
|
||||
|
||||
// the arg is if we redownload
|
||||
loc.download_and_import(false) or { panic(err) }
|
||||
println('Data import complete')
|
||||
|
||||
// // Example 1: Search for a city
|
||||
// println('\nSearching for London...')
|
||||
// results := loc.search('London', 'GB', 5, true) or { panic(err) }
|
||||
// for result in results {
|
||||
// println('${result.city.name}, ${result.country.name} (${result.country.iso2})')
|
||||
// println('Coordinates: ${result.city.latitude}, ${result.city.longitude}')
|
||||
// println('Population: ${result.city.population}')
|
||||
// println('Timezone: ${result.city.timezone}')
|
||||
// println('---')
|
||||
// }
|
||||
|
||||
// // Example 2: Search near coordinates (10km radius from London)
|
||||
// println('\nSearching for cities within 10km of London...')
|
||||
// nearby := loc.search_near(51.5074, -0.1278, 10.0, 5) or { panic(err) }
|
||||
// for result in nearby {
|
||||
// println('${result.city.name}, ${result.country.name}')
|
||||
// println('Distance from center: Approx ${result.similarity:.1f}km')
|
||||
// println('---')
|
||||
// }
|
||||
|
||||
// // Example 3: Fuzzy search in a specific country
|
||||
// println('\nFuzzy searching for "New" in United States...')
|
||||
// us_cities := loc.search('New', 'US', 5, true) or { panic(err) }
|
||||
// for result in us_cities {
|
||||
// println('${result.city.name}, ${result.country.name}')
|
||||
// println('State: ${result.city.state_name} (${result.city.state_code})')
|
||||
// println('Population: ${result.city.population}')
|
||||
// println('---')
|
||||
// }
|
||||
64
examples/data/location/location_example_tcc.vsh
Executable file
64
examples/data/location/location_example_tcc.vsh
Executable file
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.clients.postgresql_client
|
||||
import freeflowuniverse.herolib.data.location
|
||||
|
||||
// Configure PostgreSQL client
|
||||
heroscript := "
|
||||
!!postgresql_client.configure
|
||||
name:'test'
|
||||
user: 'postgres'
|
||||
port: 5432
|
||||
host: 'localhost'
|
||||
password: '1234'
|
||||
dbname: 'postgres'
|
||||
"
|
||||
|
||||
// Process the heroscript configuration
|
||||
postgresql_client.play(heroscript: heroscript)!
|
||||
|
||||
// Get the configured client
|
||||
mut db_client := postgresql_client.get(name: "test")!
|
||||
|
||||
|
||||
// Create a new location instance
|
||||
mut loc := location.new(mut db_client, false) or { panic(err) }
|
||||
println('Location database initialized')
|
||||
|
||||
// Initialize the database (downloads and imports data)
|
||||
// This only needs to be done once or when updating data
|
||||
println('Downloading and importing location data (this may take a few minutes)...')
|
||||
|
||||
// the arg is if we redownload
|
||||
loc.download_and_import(false) or { panic(err) }
|
||||
println('Data import complete')
|
||||
|
||||
// // Example 1: Search for a city
|
||||
// println('\nSearching for London...')
|
||||
// results := loc.search('London', 'GB', 5, true) or { panic(err) }
|
||||
// for result in results {
|
||||
// println('${result.city.name}, ${result.country.name} (${result.country.iso2})')
|
||||
// println('Coordinates: ${result.city.latitude}, ${result.city.longitude}')
|
||||
// println('Population: ${result.city.population}')
|
||||
// println('Timezone: ${result.city.timezone}')
|
||||
// println('---')
|
||||
// }
|
||||
|
||||
// // Example 2: Search near coordinates (10km radius from London)
|
||||
// println('\nSearching for cities within 10km of London...')
|
||||
// nearby := loc.search_near(51.5074, -0.1278, 10.0, 5) or { panic(err) }
|
||||
// for result in nearby {
|
||||
// println('${result.city.name}, ${result.country.name}')
|
||||
// println('Distance from center: Approx ${result.similarity:.1f}km')
|
||||
// println('---')
|
||||
// }
|
||||
|
||||
// // Example 3: Fuzzy search in a specific country
|
||||
// println('\nFuzzy searching for "New" in United States...')
|
||||
// us_cities := loc.search('New', 'US', 5, true) or { panic(err) }
|
||||
// for result in us_cities {
|
||||
// println('${result.city.name}, ${result.country.name}')
|
||||
// println('State: ${result.city.state_name} (${result.city.state_code})')
|
||||
// println('Population: ${result.city.population}')
|
||||
// println('---')
|
||||
// }
|
||||
40
examples/data/ourdb_example.vsh
Executable file
40
examples/data/ourdb_example.vsh
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.data.ourdb
|
||||
|
||||
const test_dir = '/tmp/ourdb'
|
||||
|
||||
mut db := ourdb.new(
|
||||
record_nr_max: 16777216 - 1 // max size of records
|
||||
record_size_max: 1024
|
||||
path: test_dir
|
||||
reset: true
|
||||
)!
|
||||
|
||||
defer {
|
||||
db.destroy() or { panic('failed to destroy db: ${err}') }
|
||||
}
|
||||
|
||||
// Test set and get
|
||||
test_data := 'Hello, World!'.bytes()
|
||||
id := db.set(data: test_data)!
|
||||
|
||||
retrieved := db.get(id)!
|
||||
assert retrieved == test_data
|
||||
|
||||
assert id == 0
|
||||
|
||||
// Test overwrite
|
||||
new_data := 'Updated data'.bytes()
|
||||
id2 := db.set(id: 0, data: new_data)!
|
||||
assert id2 == 0
|
||||
|
||||
// // Verify lookup table has the correct location
|
||||
// location := db.lookup.get(id2)!
|
||||
// println('Location after update - file_nr: ${location.file_nr}, position: ${location.position}')
|
||||
|
||||
// Get and verify the updated data
|
||||
retrieved2 := db.get(id2)!
|
||||
println('Retrieved data: ${retrieved2}')
|
||||
println('Expected data: ${new_data}')
|
||||
assert retrieved2 == new_data
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.data.paramsparser
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.data.paramsparser { Params, parse }
|
||||
import time
|
||||
|
||||
33
examples/data/radixtree.vsh
Executable file
33
examples/data/radixtree.vsh
Executable file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.data.radixtree
|
||||
|
||||
mut rt := radixtree.new(path: '/tmp/radixtree_test', reset: true)!
|
||||
|
||||
// Show initial state
|
||||
println('\nInitial state:')
|
||||
rt.debug_db()!
|
||||
|
||||
// Test insert
|
||||
println('\nInserting key "test" with value "value1"')
|
||||
rt.insert('test', 'value1'.bytes())!
|
||||
|
||||
// Show state after insert
|
||||
println('\nState after insert:')
|
||||
rt.debug_db()!
|
||||
|
||||
// Print tree structure
|
||||
rt.print_tree()!
|
||||
|
||||
// Test search
|
||||
if value := rt.search('test') {
|
||||
println('\nFound value: ${value.bytestr()}')
|
||||
} else {
|
||||
println('\nError: ${err}')
|
||||
}
|
||||
|
||||
println('\nInserting key "test2" with value "value2"')
|
||||
rt.insert('test2', 'value2'.bytes())!
|
||||
|
||||
// Print tree structure
|
||||
rt.print_tree()!
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.data.resp
|
||||
import crypto.ed25519
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -cg -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
// #!/usr/bin/env -S v -n -w -cg -no-retry-compilation -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cg -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
// #!/usr/bin/env -S v -n -w -cg -d use_openssl -enable-globals run
|
||||
//-parallel-cc
|
||||
import os
|
||||
import freeflowuniverse.herolib.develop.gittools
|
||||
|
||||
mut gs := gittools.get(reload:true)!
|
||||
mut gs := gittools.get(reload: true)!
|
||||
|
||||
gs.repos_print()!
|
||||
gs.repos_print()!
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.develop.gittools
|
||||
import freeflowuniverse.herolib.osal
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.develop.gittools
|
||||
import freeflowuniverse.herolib.osal
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import os
|
||||
import freeflowuniverse.herolib.osal
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||
import os
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.develop.luadns
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.clients.openai as op
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
// import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.clients.runpod
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.clients.vastai
|
||||
import json
|
||||
@@ -24,19 +24,19 @@ create_instance_res := va.create_instance(
|
||||
println('create instance res: ${create_instance_res}')
|
||||
|
||||
attach_sshkey_to_instance_res := va.attach_sshkey_to_instance(
|
||||
id: 1
|
||||
ssh_key: "ssh-rsa AAAA..."
|
||||
id: 1
|
||||
ssh_key: 'ssh-rsa AAAA...'
|
||||
)!
|
||||
println('attach sshkey to instance res: ${attach_sshkey_to_instance_res}')
|
||||
|
||||
stop_instance_res := va.stop_instance(
|
||||
id: 1
|
||||
state: "stopped"
|
||||
id: 1
|
||||
state: 'stopped'
|
||||
)!
|
||||
println('stop instance res: ${stop_instance_res}')
|
||||
|
||||
destroy_instance_res := va.destroy_instance(
|
||||
id: 1
|
||||
id: 1
|
||||
)!
|
||||
println('destroy instance res: ${destroy_instance_res}')
|
||||
|
||||
@@ -44,23 +44,23 @@ println('destroy instance res: ${destroy_instance_res}')
|
||||
// (request failed with code 500: {"error":"server_error","msg":"Something went wrong on the server"})
|
||||
launch_instance_res := va.launch_instance(
|
||||
// Required
|
||||
num_gpus: 1,
|
||||
gpu_name: "RTX_3090",
|
||||
image: 'vastai/tensorflow',
|
||||
disk: 10,
|
||||
region: "us-west",
|
||||
num_gpus: 1
|
||||
gpu_name: 'RTX_3090'
|
||||
image: 'vastai/tensorflow'
|
||||
disk: 10
|
||||
region: 'us-west'
|
||||
|
||||
// Optional
|
||||
env: "user=7amada, home=/home/7amada",
|
||||
env: 'user=7amada, home=/home/7amada'
|
||||
)!
|
||||
println('destroy instance res: ${launch_instance_res}')
|
||||
|
||||
start_instances_res := va.start_instances(
|
||||
ids: [1, 2, 3]
|
||||
ids: [1, 2, 3]
|
||||
)!
|
||||
println('start instances res: ${start_instances_res}')
|
||||
|
||||
start_instance_res := va.start_instance(
|
||||
id: 1
|
||||
id: 1
|
||||
)!
|
||||
println('start instance res: ${start_instance_res}')
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.hero.bootstrap
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.hero.generation
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.hero.generation
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
@@ -1 +1 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import example_actor
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.installers.sysadmintools.actrunner
|
||||
import freeflowuniverse.herolib.installers.virt.herocontainers
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.installers.fediverse.conduit
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.installers.infra.coredns as coredns_installer
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.installers.sysadmintools.daguserver
|
||||
import freeflowuniverse.herolib.installers.infra.zinit
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.installers.sysadmintools.daguserver
|
||||
|
||||
|
||||
@@ -1,34 +1,15 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.installers.infra.gitea as gitea_installer
|
||||
|
||||
// First of all, we need to set the gitea configuration
|
||||
// heroscript := "
|
||||
// !!gitea.configure
|
||||
// name:'default'
|
||||
// version:'1.22.6'
|
||||
// path: '/var/lib/git'
|
||||
// passwd: '12345678'
|
||||
// postgresql_name: 'default'
|
||||
// mail_from: 'git@meet.tf'
|
||||
// smtp_addr: 'smtp-relay.brevo.com'
|
||||
// smtp_login: 'admin'
|
||||
// smtp_port: 587
|
||||
// smtp_passwd: '12345678'
|
||||
// domain: 'meet.tf'
|
||||
// jwt_secret: ''
|
||||
// lfs_jwt_secret: ''
|
||||
// internal_token: ''
|
||||
// secret_key: ''
|
||||
// "
|
||||
|
||||
// gitea_installer.play(
|
||||
// name: 'default'
|
||||
// heroscript: heroscript
|
||||
// )!
|
||||
mut installer:= gitea_installer.get(name:'test')!
|
||||
|
||||
// Then we need to get an instace of the installer and call the install
|
||||
mut gitea := gitea_installer.get()!
|
||||
// println('gitea configs: ${gitea}')
|
||||
gitea.install()!
|
||||
gitea.start()!
|
||||
//if you want to configure using heroscript
|
||||
gitea_installer.play(heroscript:"
|
||||
!!gitea.configure name:test
|
||||
passwd:'something'
|
||||
domain: 'docs.info.com'
|
||||
")!
|
||||
|
||||
installer.start()!
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.installers.threefold.griddriver
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.installers.lang.vlang
|
||||
import freeflowuniverse.herolib.installers.sysadmintools.daguserver
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.osal
|
||||
import freeflowuniverse.herolib.installers.lang.golang
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -cg -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.installers.lang.rust
|
||||
import freeflowuniverse.herolib.installers.lang.python
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.installers.net.mycelium as mycelium_installer
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.installers.virt.podman as podman_installer
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import time
|
||||
import freeflowuniverse.herolib.installers.db.postgresql
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.installers.virt.youki
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.lang.python
|
||||
import json
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.osal { download }
|
||||
|
||||
|
||||
48
examples/osal/notifier.vsh
Executable file
48
examples/osal/notifier.vsh
Executable file
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.osal.notifier
|
||||
import os
|
||||
import time
|
||||
|
||||
fn on_file_change(event notifier.NotifyEvent, path string, args map[string]string) {
|
||||
match event {
|
||||
.create { println('File created: ${path}') }
|
||||
.modify { println('File modified: ${path}') }
|
||||
.delete { println('File deleted: ${path}') }
|
||||
.rename { println('File renamed: ${path}') }
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Create test directory and files
|
||||
test_dir := '/tmp/notifytest'
|
||||
if !os.exists(test_dir) {
|
||||
os.mkdir_all(test_dir)!
|
||||
os.write_file('${test_dir}/test.txt', 'initial content')!
|
||||
os.mkdir('${test_dir}/subdir')!
|
||||
os.write_file('${test_dir}/subdir/test2.txt', 'test content')!
|
||||
}
|
||||
|
||||
// Create a new notifier
|
||||
mut n := notifier.new('test_watcher')!
|
||||
|
||||
// Add files to watch
|
||||
n.add_watch('${test_dir}', on_file_change)!
|
||||
|
||||
// Start watching
|
||||
n.start()!
|
||||
|
||||
println('Watching files in ${test_dir} for 60 seconds...')
|
||||
println('Try these operations to test the notifier:')
|
||||
println('1. Modify a file: echo "new content" > ${test_dir}/test.txt')
|
||||
println('2. Create a file: touch ${test_dir}/newfile.txt')
|
||||
println('3. Delete a file: rm ${test_dir}/test.txt')
|
||||
println('4. Rename a file: mv ${test_dir}/test.txt ${test_dir}/renamed.txt')
|
||||
|
||||
// Keep the program running for 60 seconds
|
||||
time.sleep(60 * time.second)
|
||||
|
||||
// Clean up
|
||||
n.stop()
|
||||
println('\nWatch period ended.')
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.osal { ping }
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.builder
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.installers.infra.zinit as zinitinstaller
|
||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.osal.systemd
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.osal.ufw
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.osal.ufw
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import os
|
||||
import time
|
||||
|
||||
@@ -7,7 +7,7 @@ To be able to run examples you need to install updated version of `griddriver`.
|
||||
Create some `griddriver_install.vsh` file containing following code:
|
||||
|
||||
```vlang
|
||||
#!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.installers.tfgrid.griddriver as griddriverinstaller
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.threefold.grid.models
|
||||
import freeflowuniverse.herolib.threefold.grid as tfgrid
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.threefold.grid as tfgrid
|
||||
import freeflowuniverse.herolib.threefold.grid.models
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.threefold.grid as tfgrid
|
||||
import freeflowuniverse.herolib.threefold.grid.models
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.threefold.grid.models
|
||||
import freeflowuniverse.herolib.threefold.grid as tfgrid
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.threefold.grid.models
|
||||
import freeflowuniverse.herolib.threefold.grid as tfgrid
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.threefold.grid.models
|
||||
import freeflowuniverse.herolib.threefold.grid as tfgrid
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.threefold.grid.models
|
||||
import freeflowuniverse.herolib.threefold.grid as tfgrid
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.threefold.grid.models
|
||||
import freeflowuniverse.herolib.threefold.grid as tfgrid
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
struct DeploymentStateDB {
|
||||
secret string // to encrypt symmetric
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import log
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.threefold.grid as tfgrid
|
||||
import log
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.threefold.grid as tfgrid
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.threefold.grid as tfgrid
|
||||
import freeflowuniverse.herolib.threefold.griddriver
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
struct VMSpecs {
|
||||
deployment_name string
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
struct NodeQuery {
|
||||
location string // how to define location
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
struct WebGWArgs {
|
||||
deployment_name string
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.core.redisclient { RedisClient }
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.threefold.gridproxy
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.threefold.grid as tfgrid
|
||||
import freeflowuniverse.herolib.threefold.gridproxy
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.threefold.gridproxy
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.threefold.gridproxy
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.threefold.gridproxy
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.threefold.gridproxy
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.threefold.gridproxy
|
||||
import freeflowuniverse.herolib.threefold.gridproxy.model { NodeStatus }
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.threefold.gridproxy
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user