-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add module name handling and improve header formatting
Introduce module name processing to prevent improper imports during preprocessing and improve header formatting logic using module paths. Add a module reader utility and update Korin to derive or override module names as needed. Enhance examples to utilize the new struct import approach.
- Loading branch information
1 parent
c344b66
commit 9df37f0
Showing
6 changed files
with
80 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package test | ||
|
||
type Statistics struct { | ||
RunningMemory int // +k:named(json) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package kmod | ||
|
||
import ( | ||
"errors" | ||
"github.com/ShindouMihou/korin/internal/kstrings" | ||
"github.com/ShindouMihou/siopao/siopao" | ||
"strings" | ||
) | ||
|
||
type Module struct { | ||
Name string | ||
} | ||
|
||
func ReadModule(path string) (*Module, error) { | ||
if !kstrings.HasSuffix(path, "go.mod") { | ||
return nil, errors.New("path is not a go.mod file") | ||
} | ||
file := siopao.Open(path) | ||
|
||
reader, err := file.TextReader() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
module := Module{} | ||
if err := reader.EachLine(func(line string) { | ||
if kstrings.HasPrefix(line, "module ") { | ||
module.Name = strings.TrimPrefix(line, "module ") | ||
} | ||
}); err != nil { | ||
return nil, err | ||
} | ||
return &module, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters