Implement calling GetFood from FE
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,3 +6,4 @@ food.db
|
|||||||
food.db-shm
|
food.db-shm
|
||||||
food.db-wal
|
food.db-wal
|
||||||
main.log
|
main.log
|
||||||
|
calorie-counter-res.syso
|
||||||
|
@@ -1,14 +1,9 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Header from "$lib/components/Header.svelte";
|
import Header from "$lib/components/Header.svelte";
|
||||||
import Router from "$lib/router/Router.svelte";
|
import Router from "$lib/router/Router.svelte";
|
||||||
import { Greet } from "../wailsjs/go/main/App.js";
|
import { GetFood } from "../wailsjs/go/main/App.js";
|
||||||
|
|
||||||
let resultText: string = "Please enter your name below 👇";
|
GetFood().then((result) => console.log(result));
|
||||||
let name: string;
|
|
||||||
|
|
||||||
function greet(): void {
|
|
||||||
Greet(name).then((result) => (resultText = result));
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
5
frontend/wailsjs/go/main/App.d.ts
vendored
5
frontend/wailsjs/go/main/App.d.ts
vendored
@@ -1,6 +1,5 @@
|
|||||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||||
// This file is automatically generated. DO NOT EDIT
|
// This file is automatically generated. DO NOT EDIT
|
||||||
|
import {main} from '../models';
|
||||||
|
|
||||||
export function Foo():Promise<string>;
|
export function GetFood():Promise<Array<main.Food>>;
|
||||||
|
|
||||||
export function Greet(arg1:string):Promise<string>;
|
|
||||||
|
@@ -2,10 +2,6 @@
|
|||||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||||
// This file is automatically generated. DO NOT EDIT
|
// This file is automatically generated. DO NOT EDIT
|
||||||
|
|
||||||
export function Foo() {
|
export function GetFood() {
|
||||||
return window['go']['main']['App']['Foo']();
|
return window['go']['main']['App']['GetFood']();
|
||||||
}
|
|
||||||
|
|
||||||
export function Greet(arg1) {
|
|
||||||
return window['go']['main']['App']['Greet'](arg1);
|
|
||||||
}
|
}
|
||||||
|
17
frontend/wailsjs/go/models.ts
Normal file
17
frontend/wailsjs/go/models.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
export namespace main {
|
||||||
|
|
||||||
|
export class Food {
|
||||||
|
|
||||||
|
|
||||||
|
static createFrom(source: any = {}) {
|
||||||
|
return new Food(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(source: any = {}) {
|
||||||
|
if ('string' === typeof source) source = JSON.parse(source);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
38
main.go
38
main.go
@@ -41,9 +41,6 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// var wg sync.WaitGroup
|
|
||||||
// wg.Add(1)
|
|
||||||
|
|
||||||
dbpath := flag.String("db", "food.db", "Path to the database file")
|
dbpath := flag.String("db", "food.db", "Path to the database file")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
@@ -64,41 +61,6 @@ func main() {
|
|||||||
|
|
||||||
foodService = &FoodService{db: &db}
|
foodService = &FoodService{db: &db}
|
||||||
|
|
||||||
// _, err = foodService.GetRecent()
|
|
||||||
// if err != nil {
|
|
||||||
// Error.Printf("%++v", err)
|
|
||||||
// os.Exit(1)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// food, err := foodService.Create(Food{food: "test", amount: 1})
|
|
||||||
// if err != nil {
|
|
||||||
// Error.Printf("%++v", err)
|
|
||||||
// os.Exit(1)
|
|
||||||
// }
|
|
||||||
// log.Println(food)
|
|
||||||
|
|
||||||
// daily, err := foodService.GetDaily()
|
|
||||||
// if err != nil {
|
|
||||||
// Error.Printf("%++v", err)
|
|
||||||
// os.Exit(1)
|
|
||||||
// }
|
|
||||||
// log.Println(daily)
|
|
||||||
|
|
||||||
// test := Food{
|
|
||||||
// food: "test",
|
|
||||||
// amount: rand.Float32(),
|
|
||||||
// rowid: 766,
|
|
||||||
// }
|
|
||||||
// food, err := foodService.Update(test)
|
|
||||||
// if err != nil {
|
|
||||||
// Error.Printf("%++v", err)
|
|
||||||
// os.Exit(1)
|
|
||||||
// }
|
|
||||||
// log.Println(food)
|
|
||||||
|
|
||||||
// log.Println("done")
|
|
||||||
// wg.Wait()
|
|
||||||
|
|
||||||
// Create an instance of the app structure
|
// Create an instance of the app structure
|
||||||
app := NewApp()
|
app := NewApp()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user