Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Commit

Permalink
new: Support dist-url setting. (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj authored Apr 7, 2024
1 parent ae635be commit d88169d
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 19 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.10.2

#### 🚀 Updates

- Added a `dist-url` config setting, allowing the download host to be customized.

## 0.10.1

#### 🚀 Updates
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "go_plugin"
version = "0.10.1"
version = "0.10.2"
edition = "2021"
license = "MIT"
publish = false
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ go = "source:https://github.com/moonrepo/go-plugin/releases/download/vX.Y.Z/go_p

Go plugin can be configured with a `.prototools` file.

- `dist-url` (string) - The distribution URL to download Go archives from. Supports `{version}` and `{file}` tokens.
- `gobin` (bool) - When enabled, will inject a `GOBIN` environment variable into your shell. Defaults to `true`.

```toml
[tools.go]
dist-url = "https://..."
gobin = false
```

Expand Down
15 changes: 15 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#[derive(Debug, serde::Deserialize, serde::Serialize)]
#[serde(default, deny_unknown_fields, rename_all = "kebab-case")]
pub struct GoPluginConfig {
pub dist_url: String,
pub gobin: bool,
}

impl Default for GoPluginConfig {
fn default() -> Self {
Self {
dist_url: "https://dl.google.com/go/{file}".into(),
gobin: true,
}
}
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod config;
#[cfg(feature = "wasm")]
mod proto;
#[cfg(feature = "wasm")]
Expand Down
27 changes: 11 additions & 16 deletions src/proto.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::config::GoPluginConfig;
use crate::version::{from_go_version, to_go_version};
use extism_pdk::*;
use proto_pdk::*;
use serde::Deserialize;
use std::collections::HashMap;

#[host_fn]
Expand All @@ -12,18 +12,6 @@ extern "ExtismHost" {
static NAME: &str = "Go";
static BIN: &str = "go";

#[derive(Deserialize)]
#[serde(default, rename_all = "kebab-case")]
struct GoConfig {
gobin: bool,
}

impl Default for GoConfig {
fn default() -> Self {
Self { gobin: true }
}
}

#[plugin_fn]
pub fn register_tool(Json(_): Json<ToolMetadataInput>) -> FnResult<Json<ToolMetadataOutput>> {
Ok(Json(ToolMetadataOutput {
Expand Down Expand Up @@ -124,10 +112,17 @@ pub fn download_prebuilt(
format!("{prefix}.tar.gz")
};

let host = get_tool_config::<GoPluginConfig>()?.dist_url;

Ok(Json(DownloadPrebuiltOutput {
archive_prefix: Some("go".into()),
checksum_url: Some(format!("https://dl.google.com/go/{filename}.sha256")),
download_url: format!("https://dl.google.com/go/{filename}"),
checksum_url: Some(
host.replace("{version}", &version)
.replace("{file}", &format!("{filename}.sha256")),
),
download_url: host
.replace("{version}", &version)
.replace("{file}", &filename),
download_name: Some(filename),
..DownloadPrebuiltOutput::default()
}))
Expand Down Expand Up @@ -157,7 +152,7 @@ pub fn locate_executables(
pub fn sync_shell_profile(
Json(input): Json<SyncShellProfileInput>,
) -> FnResult<Json<SyncShellProfileOutput>> {
let config = get_tool_config::<GoConfig>()?;
let config = get_tool_config::<GoPluginConfig>()?;

Ok(Json(SyncShellProfileOutput {
check_var: "GOBIN".into(),
Expand Down
2 changes: 1 addition & 1 deletion tests/versions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ generate_resolve_versions_tests!("go-test", {
"1.11" => "1.11.13",
"1.9.0-rc2" => "1.9.0-rc2",
"1.21.0" => "1.21.0",
"1.21" => "1.21.8",
"1.21" => "1.21.9",
});

#[test]
Expand Down

0 comments on commit d88169d

Please sign in to comment.